From ebee7b280f6f299defd2c708dc803c47c88852f1 Mon Sep 17 00:00:00 2001 From: Damien Menanteau Date: Tue, 1 Oct 2024 11:33:38 +0200 Subject: [PATCH] [#674] Prepare for p4 implementation of RollbackLastCommit() - 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) --- src/vcs/git/git_impl_test.go | 4 ++-- src/vcs/p4/p4_impl.go | 3 +-- src/vcs/p4/p4_impl_test.go | 44 +++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/vcs/git/git_impl_test.go b/src/vcs/git/git_impl_test.go index ad0c05f8..cac9c451 100644 --- a/src/vcs/git/git_impl_test.go +++ b/src/vcs/git/git_impl_test.go @@ -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 @@ -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 diff --git a/src/vcs/p4/p4_impl.go b/src/vcs/p4/p4_impl.go index d21a6b39..06f70674 100644 --- a/src/vcs/p4/p4_impl.go +++ b/src/vcs/p4/p4_impl.go @@ -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") } diff --git a/src/vcs/p4/p4_impl_test.go b/src/vcs/p4/p4_impl_test.go index e30605db..2fe532e5 100644 --- a/src/vcs/p4/p4_impl_test.go +++ b/src/vcs/p4/p4_impl_test.go @@ -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 @@ -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