From bec397a3cd153d5edc4cc150d725670ed689e176 Mon Sep 17 00:00:00 2001 From: kim-codefresh Date: Wed, 11 Jan 2023 09:58:02 +0200 Subject: [PATCH] fix test Signed-off-by: kim-codefresh --- pkg/git/repository_test.go | 40 +++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/pkg/git/repository_test.go b/pkg/git/repository_test.go index 0ad8ab4c..76662618 100644 --- a/pkg/git/repository_test.go +++ b/pkg/git/repository_test.go @@ -1565,7 +1565,7 @@ func Test_validateRepoWritePermission(t *testing.T) { wantErr bool beforeFn func(r *mocks.MockRepository, w *mocks.MockWorktree) }{ - "Should fail getting git log": { + "Should fail if push context failed": { opts: nil, wantErr: true, beforeFn: func(r *mocks.MockRepository, w *mocks.MockWorktree) { @@ -1573,10 +1573,44 @@ func Test_validateRepoWritePermission(t *testing.T) { Auth: nil, Progress: os.Stderr, }). - Times(1). - Return(gg.NoErrAlreadyUpToDate). Times(1). Return(fmt.Errorf("some error")) + w.EXPECT().AddGlob(gomock.Any()). + Times(1). + Return(nil) + w.EXPECT().Commit("Validating repository write permission", gomock.Any()). + Times(1). + Return(plumbing.Hash{}, nil) + }, + }, + "Should fail if commit failed": { + opts: nil, + wantErr: true, + beforeFn: func(r *mocks.MockRepository, w *mocks.MockWorktree) { + w.EXPECT().AddGlob(gomock.Any()). + Times(1). + Return(nil) + w.EXPECT().Commit("Validating repository write permission", gomock.Any()). + Times(1). + Return(plumbing.Hash{}, fmt.Errorf("some error")) + }, + }, + "Should succeed if push context succeed": { + opts: nil, + wantErr: false, + beforeFn: func(r *mocks.MockRepository, w *mocks.MockWorktree) { + r.EXPECT().PushContext(gomock.Any(), &gg.PushOptions{ + Auth: nil, + Progress: os.Stderr, + }). + Times(1). + Return(nil) + w.EXPECT().AddGlob(gomock.Any()). + Times(1). + Return(nil) + w.EXPECT().Commit("Validating repository write permission", gomock.Any()). + Times(1). + Return(plumbing.Hash{}, nil) }, }, }