Skip to content

Commit

Permalink
[#200] Make the p4 sync always use the base_dir p4 path
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad ATWI authored and mengdaming committed Feb 1, 2023
1 parent 668f8fb commit 06527cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ func (*p4Impl) Push() error {

// Pull runs a pull operation ("p4 sync")
func (p *p4Impl) Pull() error {
return p.traceP4("sync")
path, err := p.toP4ClientPath(p.baseDir)
if err != nil {
return err
}
return p.traceP4("sync", path)
}

// Stash creates a p4 stash.
Expand Down
31 changes: 23 additions & 8 deletions src/vcs/p4/p4_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,41 @@ func Test_p4_push(t *testing.T) {

func Test_p4_pull(t *testing.T) {
testFlags := []struct {
desc string
dir string
p4Error error
expectError bool
desc string
rootDir string
dir string
clientName string
p4Error error
expectError bool
expectedArgs []string
}{
{
"p4 sync command call succeeds",
"",
filepath.FromSlash("/p4root"),
filepath.FromSlash("/p4root/base_dir"),
"test_client",
nil,
false,
[]string{"sync", "//test_client/base_dir/..."},
},
{
"p4 sync command call fails",
"",
filepath.FromSlash("/p4root"),
filepath.FromSlash("/p4root/base_dir"),
"test_client",
errors.New("p4 sync error"),
true,
[]string{"sync", "//test_client/base_dir/..."},
},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
p, _ := newP4Impl(inMemoryDepotInit, "", true)
p.traceP4Function = func(_ ...string) (err error) {
var actualArgs []string
p, _ := newP4Impl(inMemoryDepotInit, tt.dir, true)
p.rootDir = tt.rootDir
p.clientName = tt.clientName
p.traceP4Function = func(args ...string) (err error) {
actualArgs = args[4:]
return tt.p4Error
}
err := p.Pull()
Expand All @@ -278,6 +291,8 @@ func Test_p4_pull(t *testing.T) {
} else {
assert.NoError(t, err)
}

assert.Equal(t, tt.expectedArgs, actualArgs)
})
}
}
Expand Down

0 comments on commit 06527cd

Please sign in to comment.