Very rough code that can helm install
The recommended way to test code that uses exec.Cmd involves setting up a real exec.Cmd that invokes `go test` with additional arguments that fire off a specially-constructed test that behaves the way the mocked- out script would be expected to do. It's a sensible way to test exec.Cmd itself, but for code that merely invokes it, I think it makes more sense to use actual mocks.
This commit is contained in:
20
internal/run/install_test.go
Normal file
20
internal/run/install_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"github.com/golang/mock/gomock"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInstall(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
cmd := NewMockcmd(ctrl)
|
||||
cmd.EXPECT().
|
||||
Args(gomock.Eq([]string{"install", "arg1", "arg2"}))
|
||||
cmd.EXPECT().
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
install(cmd, []string{"arg1", "arg2"})
|
||||
}
|
||||
Reference in New Issue
Block a user