woodpecker-helm3/internal/run/help_test.go

77 lines
1.5 KiB
Go
Raw Normal View History

2019-12-05 22:35:25 +00:00
package run
import (
"github.com/golang/mock/gomock"
"github.com/pelotech/drone-helm3/internal/env"
2019-12-05 22:35:25 +00:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"strings"
2019-12-05 22:35:25 +00:00
"testing"
)
type HelpTestSuite struct {
suite.Suite
}
func TestHelpTestSuite(t *testing.T) {
suite.Run(t, new(HelpTestSuite))
}
func (suite *HelpTestSuite) TestNewHelp() {
cfg := env.Config{
Command: "everybody dance NOW!!",
}
help := NewHelp(cfg)
suite.Require().NotNil(help)
suite.Equal("everybody dance NOW!!", help.helmCommand)
}
func (suite *HelpTestSuite) TestPrepare() {
ctrl := gomock.NewController(suite.T())
2019-12-05 22:35:25 +00:00
defer ctrl.Finish()
mCmd := NewMockcmd(ctrl)
originalCommand := command
2019-12-05 22:35:25 +00:00
command = func(path string, args ...string) cmd {
assert.Equal(suite.T(), helmBin, path)
assert.Equal(suite.T(), []string{"help"}, args)
2019-12-05 22:35:25 +00:00
return mCmd
}
defer func() { command = originalCommand }()
2019-12-05 22:35:25 +00:00
stdout := strings.Builder{}
stderr := strings.Builder{}
2019-12-05 22:35:25 +00:00
mCmd.EXPECT().
Stdout(&stdout)
2019-12-05 22:35:25 +00:00
mCmd.EXPECT().
Stderr(&stderr)
2019-12-05 22:35:25 +00:00
cfg := env.Config{
Stdout: &stdout,
Stderr: &stderr,
}
h := NewHelp(cfg)
err := h.Prepare()
suite.NoError(err)
}
func (suite *HelpTestSuite) TestExecute() {
ctrl := gomock.NewController(suite.T())
defer ctrl.Finish()
mCmd := NewMockcmd(ctrl)
mCmd.EXPECT().
Run().
Times(2)
help := NewHelp(env.Config{Command: "help"})
help.cmd = mCmd
suite.NoError(help.Execute())
help.helmCommand = "get down on friday"
suite.EqualError(help.Execute(), "unknown command 'get down on friday'")
}