Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
dex: Add test for deployment annotation hash
Browse files Browse the repository at this point in the history
On every render helm template will generate the checksum which will be
different for unique config. Which in turn will regenerate pods for
deployment on config change.
  • Loading branch information
knrt10 committed Oct 1, 2020
1 parent 3d0f16d commit cfd9b44
Showing 1 changed file with 81 additions and 18 deletions.
99 changes: 81 additions & 18 deletions pkg/components/dex/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import (

const name = "dex"

//nolint:funlen
func TestRenderManifest(t *testing.T) {
tests := []struct {
desc string
hcl string
wantErr bool
}{
{
desc: "Valid config",
hcl: `
var tests = []struct {
desc string
hcl string
wantErr bool
}{
{
desc: "first valid config",
hcl: `
component "dex" {
ingress_host = "foo"
issuer_host = "bar"
Expand All @@ -47,7 +45,7 @@ component "dex" {
org {
name = "kinvolk"
teams = [
"lokomotive-developers",
"lokomotive-developers-1",
]
}
}
Expand All @@ -61,18 +59,51 @@ component "dex" {
}
}
`,
},
{
desc: "invalid config",
hcl: `
},
{
desc: "second valid config",
hcl: `
component "dex" {
ingress_host = "foo"
issuer_host = "bar"
connector "github" {
id = "github"
name = "Github"
config {
client_id = "clientid"
client_secret = "clientsecret"
redirect_uri = "redirecturi"
team_name_field = "slug"
org {
name = "kinvolk"
teams = [
"lokomotive-developers-2",
]
}
}
}
static_client {
name = "gangway"
id = "gangway id"
secret = "gangway secret"
redirect_uris = ["redirecturis"]
}
}
`,
},
{
desc: "invalid config",
hcl: `
component "dex" {
ingress_host = "NodePort"
}
`,
wantErr: true,
},
}
wantErr: true,
},
}

func TestRenderManifest(t *testing.T) {
for _, tc := range tests {
b, d := util.GetComponentBody(tc.hcl, name)
if d != nil {
Expand Down Expand Up @@ -104,3 +135,35 @@ component "dex" {
}
}
}

func TestConfigMapRendering(t *testing.T) {
deploymentArr := []string{}

for _, tc := range tests {
b, d := util.GetComponentBody(tc.hcl, name)
if d != nil {
t.Errorf("%s - Error getting component body: %v", tc.desc, d)
}

c, err := components.Get(name)
if err != nil {
t.Fatalf("failed getting component: %v", err)
}

d = c.LoadConfig(b, nil)
if !tc.wantErr && d.HasErrors() {
t.Errorf("%s - Valid config should not return error, got: %s", tc.desc, d)
}

m, err := c.RenderManifests()
if err != nil {
t.Errorf("%s - Rendering manifests with valid config should succeed, got: %s", tc.desc, err)
}

deploymentArr = append(deploymentArr, m["dex/templates/deployment.yaml"])
}

if deploymentArr[0] == deploymentArr[1] {
t.Errorf("expected checksum/configmap hash to be different.")
}
}

0 comments on commit cfd9b44

Please sign in to comment.