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.") + } +}