From cfd9b44107f9904d2bb5e1e14c0885bd20e36583 Mon Sep 17 00:00:00 2001 From: knrt10 Date: Thu, 1 Oct 2020 15:32:47 +0530 Subject: [PATCH] dex: Add test for deployment annotation hash 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. --- pkg/components/dex/component_test.go | 99 +++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 18 deletions(-) diff --git a/pkg/components/dex/component_test.go b/pkg/components/dex/component_test.go index f76214729..f02bdb7a8 100644 --- a/pkg/components/dex/component_test.go +++ b/pkg/components/dex/component_test.go @@ -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" @@ -47,7 +45,7 @@ component "dex" { org { name = "kinvolk" teams = [ - "lokomotive-developers", + "lokomotive-developers-1", ] } } @@ -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 { @@ -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.") + } +}