2019-12-05 22:35:25 +00:00
|
|
|
package run
|
|
|
|
|
|
|
|
import (
|
2019-12-10 00:25:47 +00:00
|
|
|
"fmt"
|
2019-12-05 22:35:25 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"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))
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
mCmd.EXPECT().
|
|
|
|
Run().
|
|
|
|
Times(1)
|
|
|
|
|
2019-12-10 00:25:47 +00:00
|
|
|
cfg := Config{
|
|
|
|
Stdout: &stdout,
|
|
|
|
Stderr: &stderr,
|
|
|
|
}
|
|
|
|
|
|
|
|
h := Help{}
|
|
|
|
err := h.Prepare(cfg)
|
|
|
|
suite.Require().Nil(err)
|
|
|
|
h.Execute()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *HelpTestSuite) TestPrepareDebugFlag() {
|
|
|
|
help := Help{}
|
|
|
|
|
|
|
|
stdout := strings.Builder{}
|
|
|
|
stderr := strings.Builder{}
|
|
|
|
cfg := Config{
|
|
|
|
Debug: true,
|
|
|
|
Stdout: &stdout,
|
|
|
|
Stderr: &stderr,
|
|
|
|
}
|
|
|
|
|
|
|
|
help.Prepare(cfg)
|
|
|
|
|
|
|
|
want := fmt.Sprintf("Generated command: '%s --debug help'\n", helmBin)
|
|
|
|
suite.Equal(want, stderr.String())
|
|
|
|
suite.Equal("", stdout.String())
|
2019-12-05 22:35:25 +00:00
|
|
|
}
|