test: Add unit tests for ChartExport
Signed-off-by: xiaomudk <xiaomudk@gmail.com>
This commit is contained in:
parent
6dc1736f15
commit
70fd920384
|
|
@ -692,16 +692,60 @@ exec: helm --kube-context dev chart pull chart --version 1.2.3 --untar --untardi
|
||||||
func Test_ChartExport(t *testing.T) {
|
func Test_ChartExport(t *testing.T) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
logger := NewLogger(&buffer, "debug")
|
logger := NewLogger(&buffer, "debug")
|
||||||
helm := MockExecer(logger, "dev")
|
tests := []struct {
|
||||||
err := helm.ChartExport("chart", "--version", "1.2.3", "--untar", "--untardir", "/tmp/dir")
|
name string
|
||||||
expected := `Exporting chart
|
helmBin string
|
||||||
exec: helm --kube-context dev chart export chart --destination --version 1.2.3 --untar --untardir /tmp/dir
|
helmVersion string
|
||||||
`
|
chartName string
|
||||||
if err != nil {
|
chartPath string
|
||||||
t.Errorf("unexpected error: %v", err)
|
chartFlags []string
|
||||||
|
listResult string
|
||||||
|
expectedError string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
helmBin: "helm",
|
||||||
|
helmVersion: "v3.6.0",
|
||||||
|
chartName: "chart",
|
||||||
|
chartPath: "path1",
|
||||||
|
chartFlags: []string{"--untar", "--untardir", "/tmp/dir"},
|
||||||
|
listResult: `Exporting chart
|
||||||
|
exec: helm --kube-context dev chart export chart --destination path1 --untar --untardir /tmp/dir
|
||||||
|
`,
|
||||||
|
expectedError: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "",
|
||||||
|
helmBin: "helm",
|
||||||
|
helmVersion: "v3.9.0",
|
||||||
|
chartName: "repo/helm-charts:0.14.0",
|
||||||
|
chartPath: "path1",
|
||||||
|
chartFlags: []string{"--untardir", "/tmp/dir"},
|
||||||
|
listResult: `Exporting repo/helm-charts:0.14.0
|
||||||
|
exec: helm --kube-context dev pull oci://repo/helm-charts --version 0.14.0 --untar --destination path1 --untardir /tmp/dir
|
||||||
|
`,
|
||||||
|
expectedError: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if buffer.String() != expected {
|
for i := range tests {
|
||||||
t.Errorf("helmexec.ChartExport()\nactual = %v\nexpect = %v", buffer.String(), expected)
|
tt := tests[i]
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
buffer.Reset()
|
||||||
|
helm := &execer{
|
||||||
|
helmBinary: tt.helmBin,
|
||||||
|
version: *semver.MustParse(tt.helmVersion),
|
||||||
|
logger: logger,
|
||||||
|
kubeContext: "dev",
|
||||||
|
runner: &mockRunner{},
|
||||||
|
}
|
||||||
|
err := helm.ChartExport(tt.chartName, tt.chartPath, tt.chartFlags...)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if buffer.String() != tt.listResult {
|
||||||
|
t.Errorf("helmexec.ChartExport()\nactual = %v\nexpect = %v", buffer.String(), tt.listResult)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue