From 697157f5d57ef674eca2d2ee5236d6f2736b2f61 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 30 May 2023 20:30:47 +0200 Subject: [PATCH] Add tests for Fetch --- pkg/commands/git_commands/sync_test.go | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pkg/commands/git_commands/sync_test.go b/pkg/commands/git_commands/sync_test.go index 23058eb92..07fe8f932 100644 --- a/pkg/commands/git_commands/sync_test.go +++ b/pkg/commands/git_commands/sync_test.go @@ -92,3 +92,40 @@ func TestSyncPush(t *testing.T) { }) } } + +func TestSyncFetch(t *testing.T) { + type scenario struct { + testName string + opts FetchOptions + test func(oscommands.ICmdObj) + } + + scenarios := []scenario{ + { + testName: "Fetch in foreground", + opts: FetchOptions{Background: false}, + test: func(cmdObj oscommands.ICmdObj) { + assert.True(t, cmdObj.ShouldLog()) + assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT) + assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"}) + }, + }, + { + testName: "Fetch in background", + opts: FetchOptions{Background: true}, + test: func(cmdObj oscommands.ICmdObj) { + assert.False(t, cmdObj.ShouldLog()) + assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL) + assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"}) + }, + }, + } + + for _, s := range scenarios { + s := s + t.Run(s.testName, func(t *testing.T) { + instance := buildSyncCommands(commonDeps{}) + s.test(instance.FetchCmdObj(s.opts)) + }) + } +}