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