Skip to content

Commit

Permalink
Add some integrations tests for Helm Render
Browse files Browse the repository at this point in the history
  • Loading branch information
tete17 committed May 10, 2020
1 parent 18774dc commit b61567b
Showing 1 changed file with 185 additions and 0 deletions.
185 changes: 185 additions & 0 deletions integration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,188 @@ spec:
})
}
}

func TestHelmRender(t *testing.T) {
if testing.Short() || RunOnGCP() {
t.Skip("skipping kind integration test")
}

tests := []struct {
description string
builds []build.Artifact
labels []deploy.Labeller
helmReleases []latest.HelmRelease
expectedOut string
}{
{
description: "Bare bones render",
builds: []build.Artifact{
{
ImageName: "gke-loadbalancer",
Tag: "gke-loadbalancer:test",
},
},
labels: []deploy.Labeller{},
helmReleases: []latest.HelmRelease{{
Name: "gke_loadbalancer",
ChartPath: "testdata/gke_loadbalancer/loadbalancer-helm",
Values: map[string]string{
"image": "gke-loadbalancer",
},
}},
expectedOut: `---
# Source: loadbalancer-helm/templates/k8s.yaml
apiVersion: v1
kind: Service
metadata:
name: gke-loadbalancer
labels:
app: gke-loadbalancer
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 3000
protocol: TCP
name: http
selector:
app: "gke-loadbalancer"
---
# Source: loadbalancer-helm/templates/k8s.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: gke-loadbalancer
labels:
app: gke-loadbalancer
spec:
replicas: 1
selector:
matchLabels:
app: gke-loadbalancer
template:
metadata:
labels:
app: gke-loadbalancer
spec:
containers:
- name: gke-container
image: gke-loadbalancer:test
ports:
- containerPort: 3000
`,
},
{
description: "A more complex template",
builds: []build.Artifact{
{
ImageName: "gcr.io/k8s-skaffold/skaffold-helm",
Tag: "gcr.io/k8s-skaffold/skaffold-helm:sha256-nonsenslettersandnumbers",
},
},
labels: []deploy.Labeller{},
helmReleases: []latest.HelmRelease{{
Name: "skaffold-helm",
ChartPath: "testdata/helm/skaffold-helm",
Values: map[string]string{
"image": "gcr.io/k8s-skaffold/skaffold-helm",
},
}},
expectedOut: `---
# Source: skaffold-helm/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: skaffold-helm-skaffold-helm
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
release: skaffold-helm
heritage: Helm
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
name: nginx
selector:
app: skaffold-helm
release: skaffold-helm
---
# Source: skaffold-helm/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-helm
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
release: skaffold-helm
heritage: Helm
spec:
replicas: 1
selector:
matchLabels:
app: skaffold-helm
release: skaffold-helm
template:
metadata:
labels:
app: skaffold-helm
release: skaffold-helm
spec:
containers:
- name: skaffold-helm
image: gcr.io/k8s-skaffold/skaffold-helm:sha256-nonsenslettersandnumbers
imagePullPolicy:
ports:
- containerPort: 80
resources:
{}
---
# Source: skaffold-helm/templates/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: skaffold-helm-skaffold-helm
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
release: skaffold-helm
heritage: Helm
annotations:
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: skaffold-helm-skaffold-helm
servicePort: 80
`,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
deployer := deploy.NewHelmDeployer(&runcontext.RunContext{
Cfg: latest.Pipeline{
Deploy: latest.DeployConfig{
DeployType: latest.DeployType{
HelmDeploy: &latest.HelmDeploy{
Releases: test.helmReleases,
},
},
},
},
})
var b bytes.Buffer
err := deployer.Render(context.Background(), &b, test.builds, test.labels, "")

t.CheckNoError(err)
t.CheckDeepEqual(test.expectedOut, b.String())
})
}
}

0 comments on commit b61567b

Please sign in to comment.