This commit is contained in:
admju
2024-09-10 13:05:48 +00:00
parent 13025746e6
commit 75b7b94a50
10 changed files with 277 additions and 37 deletions

View File

@@ -30,15 +30,16 @@ type MockCommandExecutor struct {
// Used to stub the return of the Output method
// Could add other properties depending on testing needs
output string
err error
}
// Implements the commandExecutor interface
func (m *MockCommandExecutor) Output() ([]byte, error) {
return []byte(m.output), nil
return []byte(m.output), m.err
}
func (m *MockCommandExecutor) CombinedOutput() ([]byte, error) {
return []byte(m.output), nil
return []byte(m.output), m.err
}
//
@@ -74,7 +75,26 @@ func getCmdsKubectl(mock bool, outputs map[string]string) (KubectlCommand) {
cmd := KubectlCommand{Bin: "mock", Exec: mock}
return cmd
} else {
bin := filepath.Join(TEST_BIN_DIR, "Kubectl")
bin := filepath.Join(TEST_BIN_DIR, "kubectl")
os.Chmod(bin, 0700)
cmd := KubectlCommand{Bin: bin}
cmd.New()
return cmd
}
}
func getCmdKubectlError(mock bool, output string, err error) (KubectlCommand) {
if mock == true {
mock := func(name string, args ...string) commandExecutor {
return &MockCommandExecutor{output: output, err: err}
}
cmd := KubectlCommand{Bin: "mock", Exec: mock}
return cmd
} else {
bin := filepath.Join(TEST_BIN_DIR, "kubectl")
os.Chmod(bin, 0700)
cmd := KubectlCommand{Bin: bin}