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

Commit

Permalink
pkg/components: use NewConfig() when getting default config for tests
Browse files Browse the repository at this point in the history
So we don't rely on other packages while running unit tests.

Refs #992

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Dec 3, 2020
1 parent 26d5121 commit 1015951
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 34 deletions.
12 changes: 3 additions & 9 deletions pkg/components/dex/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package dex_test
import (
"testing"

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

Expand Down Expand Up @@ -110,10 +110,7 @@ func TestRenderManifest(t *testing.T) {
t.Fatalf("%s - Error getting component body: %v", tc.desc, d)
}

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

d = c.LoadConfig(b, nil)

Expand Down Expand Up @@ -145,10 +142,7 @@ func TestDeploymentAnnotationHashChange(t *testing.T) {
t.Fatalf("%s - Error getting component body: %v", tc.desc, d)
}

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

d = c.LoadConfig(b, nil)
if !tc.wantErr && d.HasErrors() {
Expand Down
7 changes: 2 additions & 5 deletions pkg/components/gangway/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package gangway_test
import (
"testing"

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

Expand Down Expand Up @@ -62,10 +62,7 @@ component "gangway" {
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)
}
c := gangway.NewConfig()

d = c.LoadConfig(b, nil)

Expand Down
7 changes: 2 additions & 5 deletions pkg/components/httpbin/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package httpbin_test
import (
"testing"

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

Expand Down Expand Up @@ -54,10 +54,7 @@ component "httpbin" {
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)
}
c := httpbin.NewConfig()

d = c.LoadConfig(b, nil)

Expand Down
7 changes: 2 additions & 5 deletions pkg/components/inspektor-gadget/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ import (
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/yaml"

"github.com/kinvolk/lokomotive/pkg/components"
inspektorgadget "github.com/kinvolk/lokomotive/pkg/components/inspektor-gadget"
"github.com/kinvolk/lokomotive/pkg/components/util"
)

func renderManifests(configHCL string) (map[string]string, error) {
component, err := components.Get("inspektor-gadget")
if err != nil {
return nil, err
}
component := inspektorgadget.NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, "inspektor-gadget")
if diagnostics != nil {
Expand Down
7 changes: 2 additions & 5 deletions pkg/components/rook/component_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"

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

Expand Down Expand Up @@ -102,10 +102,7 @@ component "rook" {
func renderManifests(t *testing.T, configHCL string) map[string]string {
name := "rook"

component, err := components.Get(name)
if err != nil {
t.Fatalf("Getting component %q: %v", name, err)
}
component := rook.NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, name)
if diagnostics != nil {
Expand Down
7 changes: 2 additions & 5 deletions pkg/components/web-ui/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ import (
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"sigs.k8s.io/yaml"

"github.com/kinvolk/lokomotive/pkg/components"
"github.com/kinvolk/lokomotive/pkg/components/util"
webui "github.com/kinvolk/lokomotive/pkg/components/web-ui"
)

func renderManifests(configHCL string) (map[string]string, error) {
component, err := components.Get("web-ui")
if err != nil {
return nil, err
}
component := webui.NewConfig()

body, diagnostics := util.GetComponentBody(configHCL, "web-ui")
if diagnostics != nil {
Expand Down

0 comments on commit 1015951

Please sign in to comment.