Skip to content

Commit

Permalink
[#674] Prepare for p4 implementation of RollbackLastCommit()
Browse files Browse the repository at this point in the history
- renamed test cases from restore to revert_local
- renamed git test case from revert to rollback_last_commit
- added p4 rollback_last_commit test case (wip)
  • Loading branch information
mengdaming committed Oct 1, 2024
1 parent abe7daa commit ebee7b2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/vcs/git/git_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func Test_git_commit(t *testing.T) {
}
}

func Test_git_restore(t *testing.T) {
func Test_git_revert_local(t *testing.T) {
testFlags := []struct {
desc string
gitError error
Expand Down Expand Up @@ -463,7 +463,7 @@ func Test_git_restore(t *testing.T) {
}
}

func Test_git_revert(t *testing.T) {
func Test_git_rollback_last_commit(t *testing.T) {
testFlags := []struct {
desc string
gitError error
Expand Down
3 changes: 1 addition & 2 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func (p *p4Impl) RevertLocal(path string) error {
return p.traceP4("revert", path)
}

// Revert runs a p4 revert operation.
// TODO: VCS Revert - p4 revert
// RollbackLastCommit runs a p4 revert operation.
func (*p4Impl) RollbackLastCommit() error {
return errors.New("VCS revert operation not yet available for p4")
}
Expand Down
44 changes: 43 additions & 1 deletion src/vcs/p4/p4_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func Test_p4_submit(t *testing.T) {
}
}

func Test_p4_restore(t *testing.T) {
func Test_p4_revert_local(t *testing.T) {
testFlags := []struct {
desc string
p4Error error
Expand Down Expand Up @@ -556,6 +556,48 @@ func Test_p4_restore(t *testing.T) {
}
}

func Test_p4_rollback_last_commit(t *testing.T) {
t.Skip("Work in progress")

testFlags := []struct {
desc string
p4Error error
expectError bool
expectedArgs []string
}{
{
"p4 undo command call succeeds",
nil,
false,
[]string{"undo", "--no-gpg-sign", "--no-edit", "--no-commit", "HEAD"},
},
{
"git revert command call fails",
errors.New("git revert error"),
true,
[]string{"revert", "--no-gpg-sign", "--no-edit", "--no-commit", "HEAD"},
},
}
for _, tt := range testFlags {
t.Run(tt.desc, func(t *testing.T) {
var actualArgs []string
p, _ := newP4Impl(inMemoryDepotInit, "", true)
p.traceP4Function = func(args ...string) (err error) {
actualArgs = args[2:]
return tt.p4Error
}

err := p.RollbackLastCommit()
if tt.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.expectedArgs, actualArgs)
})
}
}

func Test_convert_to_p4_client_path(t *testing.T) {
testFlags := []struct {
desc string
Expand Down

0 comments on commit ebee7b2

Please sign in to comment.