Adds test.
This commit is contained in:
parent
dbe56ba613
commit
128fc21efb
@ -78,7 +78,7 @@ func Init() Config {
|
||||
// read config file
|
||||
configFileData, err := getConfigFileData(cfg.ConfigFile)
|
||||
if err != nil {
|
||||
log.Fatalf("[FATAL] Unable to read configuration file")
|
||||
log.Fatalf("[FATAL] Unable to read configuration file: %v", err)
|
||||
}
|
||||
updateValues(&cfg, configFileData)
|
||||
|
||||
|
@ -1,19 +1,47 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
cfg := Init()
|
||||
if cfg.AllowAdminNoMutateToggle != "7b068a99-c02b-410a-bd59-3514bac85e7a" {
|
||||
t.Errorf("Init() returned incorrect value for AllowAdminNoMutateToggle, got %v, wanted %v", cfg.AllowAdminNoMutateToggle, "7b068a99-c02b-410a-bd59-3514bac85e7a")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOSEnv(t *testing.T) {
|
||||
expected := "foo"
|
||||
os.Setenv("TEST_ENV", expected)
|
||||
result := getOSEnv("TEST_ENV", "bar")
|
||||
|
||||
if result != expected {
|
||||
t.Errorf("getOSEnv() returned incorrect value, got %s, wanted %s", result, expected)
|
||||
}
|
||||
|
||||
os.Unsetenv("TEST_ENV")
|
||||
result = getOSEnv("TEST_ENV", expected)
|
||||
if result != expected {
|
||||
t.Errorf("getOSEnv() returned incorrect value, got %s, wanted %s", result, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateValues(t *testing.T) {
|
||||
cfg := Config{
|
||||
AllowAdminNoMutate: false,
|
||||
AllowAdminNoMutateToggle: "7b068a99-c02b-410a-bd59-3514bac85e7a",
|
||||
DockerhubRegistry: "registry.hub.docker.com",
|
||||
NameSpace: "ingress-nginx",
|
||||
}
|
||||
cfgFile := configFileStruct{
|
||||
AllowAdminNoMutate: true,
|
||||
AllowAdminNoMutateToggle: "test-token",
|
||||
DockerhubRegistry: "registry.example.com",
|
||||
Kubernetes: KubernetesStruct{
|
||||
Namespace: "example-namespace",
|
||||
},
|
||||
}
|
||||
|
||||
updateValues(&cfg, cfgFile)
|
||||
@ -26,13 +54,10 @@ func TestUpdateValues(t *testing.T) {
|
||||
if cfg.DockerhubRegistry != cfgFile.DockerhubRegistry {
|
||||
t.Errorf("updateValues() returned incorrect value for DockerhubRegistry, got %v, wanted %v", cfg.DockerhubRegistry, cfgFile.DockerhubRegistry)
|
||||
}
|
||||
if cfg.NameSpace != cfgFile.Kubernetes.Namespace {
|
||||
t.Errorf("updateValues() returned incorrect value for NameSpace, got %v, wanted %v", cfg.NameSpace, cfgFile.Kubernetes.Namespace)
|
||||
}
|
||||
/*
|
||||
if cfg.DockerhubRegistry == "registry.hub.docker.com" && configFileData.DockerhubRegistry != "registry.hub.docker.com" {
|
||||
cfg.DockerhubRegistry = configFileData.DockerhubRegistry
|
||||
}
|
||||
if cfg.NameSpace == "ingress-nginx" && configFileData.Kubernetes.Namespace != "ingress-nginx" {
|
||||
cfg.NameSpace = configFileData.Kubernetes.Namespace
|
||||
}
|
||||
if cfg.ServiceName == "webhook" && configFileData.Kubernetes.ServiceName != "webhook" {
|
||||
cfg.ServiceName = configFileData.Kubernetes.ServiceName
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user