diff options
Diffstat (limited to 'pkg/commands/oscommands')
-rw-r--r-- | pkg/commands/oscommands/dummies.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/fake_cmd_obj_runner.go | 28 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 2 | ||||
-rw-r--r-- | pkg/commands/oscommands/os_test.go | 2 |
4 files changed, 26 insertions, 8 deletions
diff --git a/pkg/commands/oscommands/dummies.go b/pkg/commands/oscommands/dummies.go index 3bb8429bd..ba60374f4 100644 --- a/pkg/commands/oscommands/dummies.go +++ b/pkg/commands/oscommands/dummies.go @@ -10,7 +10,7 @@ func NewDummyOSCommand() *OSCommand { return NewOSCommand(utils.NewDummyCommon()) } -func NewCmdObjBuilderDummy(runner ICmdObjRunner) ICmdObjBuilder { +func NewDummyCmdObjBuilder(runner ICmdObjRunner) *CmdObjBuilder { return &CmdObjBuilder{ runner: runner, logCmdObj: func(ICmdObj) {}, diff --git a/pkg/commands/oscommands/fake_cmd_obj_runner.go b/pkg/commands/oscommands/fake_cmd_obj_runner.go index 09431bb20..9a8a1e798 100644 --- a/pkg/commands/oscommands/fake_cmd_obj_runner.go +++ b/pkg/commands/oscommands/fake_cmd_obj_runner.go @@ -36,9 +36,11 @@ func (self *FakeCmdObjRunner) RunWithOutput(cmdObj ICmdObj) (string, error) { } expectedCmd := self.expectedCmds[self.expectedCmdIndex] + output, err := expectedCmd(cmdObj) + self.expectedCmdIndex++ - return expectedCmd(cmdObj) + return output, err } func (self *FakeCmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line string) (bool, error)) error { @@ -72,13 +74,29 @@ func (self *FakeCmdObjRunner) ExpectFunc(fn func(cmdObj ICmdObj) (string, error) func (self *FakeCmdObjRunner) Expect(expectedCmdStr string, output string, err error) *FakeCmdObjRunner { self.ExpectFunc(func(cmdObj ICmdObj) (string, error) { cmdStr := cmdObj.ToString() - if cmdStr != expectedCmdStr { - assert.Equal(self.t, expectedCmdStr, cmdStr, fmt.Sprintf("expected command %d to be %s, but was %s", self.expectedCmdIndex+1, expectedCmdStr, cmdStr)) - return "", errors.New("expected cmd") - } + assert.Equal(self.t, expectedCmdStr, cmdStr, fmt.Sprintf("expected command %d to be %s, but was %s", self.expectedCmdIndex+1, expectedCmdStr, cmdStr)) + + return output, err + }) + + return self +} + +func (self *FakeCmdObjRunner) ExpectArgs(expectedArgs []string, output string, err error) *FakeCmdObjRunner { + self.ExpectFunc(func(cmdObj ICmdObj) (string, error) { + args := cmdObj.GetCmd().Args + assert.EqualValues(self.t, expectedArgs, args, fmt.Sprintf("command %d did not match expectation", self.expectedCmdIndex+1)) return output, err }) return self } + +func (self *FakeCmdObjRunner) CheckForMissingCalls() { + if self.expectedCmdIndex < len(self.expectedCmds) { + self.t.Errorf("expected command %d to be called, but was not", self.expectedCmdIndex+1) + } + + return +} diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index d906e584a..9695472ae 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -137,7 +137,7 @@ func (c *OSCommand) SetRemoveFile(f func(string) error) { } // FileType tells us if the file is a file, directory or other -func (c *OSCommand) FileType(path string) string { +func FileType(path string) string { fileInfo, err := os.Stat(path) if err != nil { return "other" diff --git a/pkg/commands/oscommands/os_test.go b/pkg/commands/oscommands/os_test.go index 73c846fb0..04e940f03 100644 --- a/pkg/commands/oscommands/os_test.go +++ b/pkg/commands/oscommands/os_test.go @@ -164,7 +164,7 @@ func TestOSCommandFileType(t *testing.T) { for _, s := range scenarios { s.setup() - s.test(NewDummyOSCommand().FileType(s.path)) + s.test(FileType(s.path)) _ = os.RemoveAll(s.path) } } |