2019-12-27 23:06:32 +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-27 23:06:32 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DepUpdateTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
ctrl *gomock.Controller
|
|
|
|
mockCmd *Mockcmd
|
|
|
|
originalCommand func(string, ...string) cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *DepUpdateTestSuite) BeforeTest(_, _ string) {
|
|
|
|
suite.ctrl = gomock.NewController(suite.T())
|
|
|
|
suite.mockCmd = NewMockcmd(suite.ctrl)
|
|
|
|
|
|
|
|
suite.originalCommand = command
|
|
|
|
command = func(path string, args ...string) cmd { return suite.mockCmd }
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *DepUpdateTestSuite) AfterTest(_, _ string) {
|
|
|
|
command = suite.originalCommand
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDepUpdateTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(DepUpdateTestSuite))
|
|
|
|
}
|
|
|
|
|
2020-01-16 21:50:04 +00:00
|
|
|
func (suite *DepUpdateTestSuite) TestNewDepUpdate() {
|
|
|
|
cfg := env.Config{
|
|
|
|
Chart: "scatterplot",
|
|
|
|
}
|
|
|
|
d := NewDepUpdate(cfg)
|
2020-01-17 18:13:53 +00:00
|
|
|
suite.Equal("scatterplot", d.chart)
|
2020-01-16 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 23:06:32 +00:00
|
|
|
func (suite *DepUpdateTestSuite) TestPrepareAndExecute() {
|
|
|
|
defer suite.ctrl.Finish()
|
|
|
|
|
|
|
|
stdout := strings.Builder{}
|
|
|
|
stderr := strings.Builder{}
|
2020-01-17 18:13:53 +00:00
|
|
|
cfg := env.Config{
|
|
|
|
Chart: "your_top_songs_2019",
|
2019-12-27 23:06:32 +00:00
|
|
|
Stdout: &stdout,
|
|
|
|
Stderr: &stderr,
|
|
|
|
}
|
|
|
|
|
|
|
|
command = func(path string, args ...string) cmd {
|
|
|
|
suite.Equal(helmBin, path)
|
|
|
|
suite.Equal([]string{"dependency", "update", "your_top_songs_2019"}, args)
|
|
|
|
|
|
|
|
return suite.mockCmd
|
|
|
|
}
|
|
|
|
suite.mockCmd.EXPECT().
|
|
|
|
Stdout(&stdout)
|
|
|
|
suite.mockCmd.EXPECT().
|
|
|
|
Stderr(&stderr)
|
|
|
|
suite.mockCmd.EXPECT().
|
|
|
|
Run().
|
|
|
|
Times(1)
|
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
d := NewDepUpdate(cfg)
|
2019-12-27 23:06:32 +00:00
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
suite.Require().NoError(d.Prepare())
|
2020-01-16 23:30:21 +00:00
|
|
|
suite.NoError(d.Execute())
|
2019-12-27 23:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *DepUpdateTestSuite) TestPrepareChartRequired() {
|
2020-01-17 18:13:53 +00:00
|
|
|
d := NewDepUpdate(env.Config{})
|
2019-12-27 23:06:32 +00:00
|
|
|
|
|
|
|
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
|
|
|
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
|
|
|
|
2020-01-17 18:13:53 +00:00
|
|
|
err := d.Prepare()
|
2019-12-27 23:06:32 +00:00
|
|
|
suite.EqualError(err, "chart is required")
|
|
|
|
}
|