Skip to content

Commit

Permalink
Add kubectl render labeller unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Buerkle <armin.buerkle@alfatraining.de>
  • Loading branch information
arminbuerkle committed Jan 22, 2020
1 parent 531958a commit d15f474
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions pkg/skaffold/deploy/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ func TestKubectlRender(t *testing.T) {
tests := []struct {
description string
builds []build.Artifact
labels []Labeller
input string
expected string
}{
{
description: "normal render",
Expand All @@ -491,12 +493,26 @@ func TestKubectlRender(t *testing.T) {
Tag: "gcr.io/k8s-skaffold/skaffold:test",
},
},
labels: []Labeller{},
input: `apiVersion: v1
kind: Pod
metadata:
namespace: default
spec:
containers:
- image: gcr.io/k8s-skaffold/skaffold
name: skaffold
`,
expected: `apiVersion: v1
kind: Pod
metadata:
labels:
skaffold.dev/deployer: kubectl
namespace: default
spec:
containers:
- image: gcr.io/k8s-skaffold/skaffold:test
name: skaffold
`,
},
{
Expand All @@ -512,38 +528,57 @@ spec:
},
},
input: `apiVersion: v1
kind: Pod
spec:
containers:
- image: gcr.io/project/image1
name: image1
- image: gcr.io/project/image2
name: image2
`,
kind: Pod
metadata:
namespace: default
spec:
containers:
- image: gcr.io/project/image1
name: image1
- image: gcr.io/project/image2
name: image2
`,
expected: `apiVersion: v1
kind: Pod
metadata:
labels:
skaffold.dev/deployer: kubectl
namespace: default
spec:
containers:
- image: gcr.io/project/image1:tag1
name: image1
- image: gcr.io/project/image2:tag2
name: image2
`,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
tmpDir := t.NewTempDir().
Write("deployment.yaml", test.input)

t.Override(&util.DefaultExecCommand, testutil.
CmdRunOut("kubectl version --client -ojson", kubectlVersion).
AndRunOut("kubectl --context kubecontext create --dry-run -oyaml -f deployment.yaml", test.input))
AndRunOut("kubectl --context kubecontext create --dry-run -oyaml -f "+tmpDir.Path("deployment.yaml"), test.input))

deployer := NewKubectlDeployer(&runcontext.RunContext{
WorkingDir: ".",
Cfg: latest.Pipeline{
Deploy: latest.DeployConfig{
DeployType: latest.DeployType{
KubectlDeploy: &latest.KubectlDeploy{
Manifests: []string{"deployment.yaml"},
Manifests: []string{tmpDir.Path("deployment.yaml")},
},
},
},
},
KubeContext: testKubeContext,
})
var b bytes.Buffer
err := deployer.Render(context.Background(), &b, test.builds, nil, "")
err := deployer.Render(context.Background(), &b, test.builds, test.labels, "")
t.CheckNoError(err)
t.CheckDeepEqual(test.expected, b.String())
})
}
}

0 comments on commit d15f474

Please sign in to comment.