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

Commit

Permalink
httpbin: add test for manifest rendering
Browse files Browse the repository at this point in the history
Signed-off-by: knrt10 <kautilya@kinvolk.io>
  • Loading branch information
knrt10 committed Sep 15, 2020
1 parent 8e7e62e commit 1422745
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions pkg/components/httpbin/component_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 The Lokomotive Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package httpbin_test

import (
"testing"

"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

const name = "httpbin"

func TestRenderManifest(t *testing.T) {
tests := []struct {
desc string
hcl string
wantErr bool
}{
{
desc: "Valid config",
hcl: `
component "httpbin" {
ingress_host = "foo"
}
`,
},
{
desc: "invalid config",
hcl: `
component "dex" {
certmanager_cluster_issuer = "letsencrypt-staging"
}
`,
wantErr: true,
},
}

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)
}

if tc.wantErr && !d.HasErrors() {
t.Errorf("%s - Wrong config should have returned an error", tc.desc)
}

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

if len(m) == 0 {
t.Errorf("%s - Rendered manifests shouldn't be empty", tc.desc)
}
}
}

0 comments on commit 1422745

Please sign in to comment.