github.com/emmahsax/go-git-helper@v0.0.8-0.20240519163017-907b9de0fa52/cmd/setHeadRef/setHeadRef_test.go (about) 1 package setHeadRef 2 3 import ( 4 "testing" 5 ) 6 7 type MockExecutor struct { 8 Args []string 9 Command string 10 Debug bool 11 Output []byte 12 } 13 14 func (me *MockExecutor) Exec(execType string, command string, args ...string) ([]byte, error) { 15 me.Command = command 16 me.Args = args 17 return me.Output, nil 18 } 19 20 func Test_execute(t *testing.T) { 21 tests := []struct { 22 expectedArgs []string 23 }{ 24 {expectedArgs: []string{"symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main"}}, 25 } 26 27 for _, test := range tests { 28 executor := &MockExecutor{Debug: true} 29 shr := newSetHeadRef("main", true, executor) 30 shr.execute() 31 32 if executor.Command != "git" { 33 t.Errorf("unexpected command received: expected %s, but got %s", "git", executor.Command) 34 } 35 36 if len(executor.Args) != len(test.expectedArgs) { 37 t.Errorf("unexpected args received: expected %v, but got %v", test.expectedArgs, executor.Args) 38 } 39 40 for i, v := range executor.Args { 41 if v != test.expectedArgs[i] { 42 t.Errorf("unexpected args received: expected %v, but got %v", test.expectedArgs, executor.Args) 43 } 44 } 45 } 46 }