Skip to content

Commit

Permalink
Add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
tete17 authored and Miguel Sacristan committed Apr 9, 2020
1 parent 572fd3d commit 36b12b0
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,46 +982,101 @@ func TestHelmRender(t *testing.T) {
shouldErr bool
commands util.Command
runContext *runcontext.RunContext
outputFile string
expected string
builds []build.Artifact
}{
{
description: "error if version can't be retrieved",
shouldErr: true,
commands: testutil.CmdRunErr("helm version", fmt.Errorf("yep not working")),
runContext: makeRunContext(testDeployConfig, false),
},
{
description: "normal render v2",
shouldErr: false,
commands: testutil.
CmdRunWithOutput("helm version", version21).
AndRun("helm --kube-context kubecontext template examples/test --name skaffold-helm --set image=skaffold-helm --kubeconfig kubeconfig"),
AndRun("helm --kube-context kubecontext template examples/test --name skaffold-helm --set-string image=skaffold-helm:tag1 --set image=skaffold-helm --kubeconfig kubeconfig"),
runContext: makeRunContext(testDeployConfig, false),
builds: []build.Artifact{
{
ImageName: "skaffold-helm",
Tag: "skaffold-helm:tag1",
}},
},
{
description: "normal render v3",
shouldErr: false,
commands: testutil.
CmdRunWithOutput("helm version", version31).
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set image=skaffold-helm --kubeconfig kubeconfig"),
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set-string image=skaffold-helm:tag1 --set image=skaffold-helm --kubeconfig kubeconfig"),
runContext: makeRunContext(testDeployConfig, false),
builds: []build.Artifact{
{
ImageName: "skaffold-helm",
Tag: "skaffold-helm:tag1",
}},
},
{
description: "render to a file",
shouldErr: false,
commands: testutil.
CmdRunWithOutput("helm version", version31).
AndRunWithOutput("helm --kube-context kubecontext template skaffold-helm examples/test --set-string image=skaffold-helm:tag1 --set image=skaffold-helm --kubeconfig kubeconfig",
"Dummy Output"),
runContext: makeRunContext(testDeployConfig, false),
outputFile: "dummy.yaml",
expected: "Dummy Output",
builds: []build.Artifact{
{
ImageName: "skaffold-helm",
Tag: "skaffold-helm:tag1",
}},
},
{
description: "render with templated config",
shouldErr: false,
commands: testutil.
CmdRunWithOutput("helm version", version31).
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set image=skaffold-helm --set image.name=<no value> --set image.tag=<no value> --set missing.key=<no value> --set other.key=<no value> --set some.key=somevalue --kubeconfig kubeconfig"),
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set-string image=skaffold-helm:tag1 --set image=skaffold-helm --set image.name=<no value> --set image.tag=<no value> --set missing.key=<no value> --set other.key=<no value> --set some.key=somevalue --kubeconfig kubeconfig"),
runContext: makeRunContext(testDeployConfigTemplated, false),
builds: []build.Artifact{
{
ImageName: "skaffold-helm",
Tag: "skaffold-helm:tag1",
}},
},
{
description: "render with namespace",
shouldErr: false,
commands: testutil.CmdRunWithOutput("helm version", version31).
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set image=skaffold-helm --namespace testNamespace --kubeconfig kubeconfig"),
AndRun("helm --kube-context kubecontext template skaffold-helm examples/test --set-string image=skaffold-helm:tag1 --set image=skaffold-helm --namespace testNamespace --kubeconfig kubeconfig"),
runContext: makeRunContext(testDeployNamespacedConfig, false),
builds: []build.Artifact{
{
ImageName: "skaffold-helm",
Tag: "skaffold-helm:tag1",
}},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
file := ""
if test.outputFile != "" {
file = t.NewTempDir().Path(test.outputFile)
}

deployer := NewHelmDeployer(test.runContext)

t.Override(&util.DefaultExecCommand, test.commands)
err := deployer.Render(context.Background(), ioutil.Discard, []build.Artifact{}, nil, "")
err := deployer.Render(context.Background(), ioutil.Discard, test.builds, nil, file)
t.CheckError(test.shouldErr, err)

if file != "" {
dat, _ := ioutil.ReadFile(file)
t.CheckDeepEqual(string(dat), test.expected)
}
})
}
}
Expand Down

0 comments on commit 36b12b0

Please sign in to comment.