1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00
Files
chart-testing/pkg/tool/cmdexecutor_test.go
Carlos Tadeu Panato Junior 68f3fffe62 Upgrade go1.19, helm update and add golangci-lint job (#460)
* upgrade to go1.19

Signed-off-by: cpanato <ctadeu@gmail.com>

* add golangci-lint

Signed-off-by: cpanato <ctadeu@gmail.com>

* fix lints and Replace github.com/pkg/errors dependency with native error wrapping

Signed-off-by: cpanato <ctadeu@gmail.com>

* update install kind cluster

Signed-off-by: cpanato <ctadeu@gmail.com>

* update tests

Signed-off-by: cpanato <ctadeu@gmail.com>

* use errors.new

Signed-off-by: cpanato <ctadeu@gmail.com>

Signed-off-by: cpanato <ctadeu@gmail.com>
2022-09-16 15:59:15 +02:00

77 lines
1.9 KiB
Go

package tool
import (
"testing"
"github.com/stretchr/testify/mock"
)
type fakeProcessExecutor struct {
mock.Mock
}
func (c *fakeProcessExecutor) RunProcess(executable string, execArgs ...interface{}) error {
c.Called(executable, execArgs[0])
return nil
}
func TestCmdTemplateExecutor_RunCommand(t *testing.T) {
type args struct {
cmdTemplate string
data interface{}
}
tests := []struct {
name string
args args
wantErr bool
validate func(t *testing.T, executor *fakeProcessExecutor)
}{
{
name: "command without arguments",
args: args{
cmdTemplate: "echo",
data: nil,
},
validate: func(t *testing.T, executor *fakeProcessExecutor) {
executor.AssertCalled(t, "RunProcess", "echo", []string{})
},
wantErr: false,
},
{
name: "command with args",
args: args{
cmdTemplate: "echo hello world",
},
validate: func(t *testing.T, executor *fakeProcessExecutor) {
executor.AssertCalled(t, "RunProcess", "echo", []string{"hello", "world"})
},
wantErr: false,
},
{
name: "interpolate args",
args: args{
cmdTemplate: "helm unittest --helm3 -f tests/*.yaml {{ .Path }}",
data: map[string]string{"Path": "charts/my-chart"},
},
validate: func(t *testing.T, executor *fakeProcessExecutor) {
executor.AssertCalled(t, "RunProcess", "helm", []string{"unittest", "--helm3", "-f", "tests/*.yaml", "charts/my-chart"})
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
processExecutor := new(fakeProcessExecutor)
processExecutor.On("RunProcess", mock.Anything, mock.Anything).Return(nil)
templateExecutor := CmdTemplateExecutor{
exec: processExecutor,
}
if err := templateExecutor.RunCommand(tt.args.cmdTemplate, tt.args.data); (err != nil) != tt.wantErr {
t.Errorf("RunCommand() error = %v, wantErr %v", err, tt.wantErr)
}
tt.validate(t, processExecutor)
})
}
}