|
|
@@ -155,3 +155,82 @@ func TestGetCloudCostConfigPath(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+func TestEnvVarsWithBackup(t *testing.T) {
|
|
|
+ t.Run("test install namespace env var", func(t *testing.T) {
|
|
|
+ t.Setenv(InstallNamespaceEnvVar, "test-namespace")
|
|
|
+ t.Setenv(KubecostNamespaceEnvVar, "kubecost-test-namespace")
|
|
|
+
|
|
|
+ ns := GetInstallNamespace()
|
|
|
+ if ns != "test-namespace" {
|
|
|
+ t.Errorf("Expected install namespace to be 'test-namespace', got '%s'", ns)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ t.Run("test kubecost namespace env var", func(t *testing.T) {
|
|
|
+ t.Setenv(KubecostNamespaceEnvVar, "kc-test-namespace")
|
|
|
+
|
|
|
+ ns := GetInstallNamespace()
|
|
|
+
|
|
|
+ if ns != "kc-test-namespace" {
|
|
|
+ t.Errorf("Expected install namespace to be 'kc-test-namespace', got '%s'", ns)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test default install namespace", func(t *testing.T) {
|
|
|
+ t.Setenv(InstallNamespaceEnvVar, "test-namespace")
|
|
|
+
|
|
|
+ ns := GetInstallNamespace()
|
|
|
+
|
|
|
+ if ns != "test-namespace" {
|
|
|
+ t.Errorf("Expected default install namespace to be 'test-namespace', got '%s'", ns)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test default install namespace", func(t *testing.T) {
|
|
|
+ ns := GetInstallNamespace()
|
|
|
+
|
|
|
+ if ns != "opencost" {
|
|
|
+ t.Errorf("Expected default install namespace to be 'opencost', got '%s'", ns)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test config bucket file with both", func(t *testing.T) {
|
|
|
+ t.Setenv(ConfigBucketEnvVar, "test-bucket")
|
|
|
+ t.Setenv(KubecostConfigBucketEnvVar, "kc-test-bucket")
|
|
|
+
|
|
|
+ configBucketFile := GetConfigBucketFile()
|
|
|
+
|
|
|
+ if configBucketFile != "test-bucket" {
|
|
|
+ t.Errorf("Expected config bucket file to be 'test-bucket', got '%s'", configBucketFile)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test config bucket file with kc", func(t *testing.T) {
|
|
|
+ t.Setenv(KubecostConfigBucketEnvVar, "kc-test-bucket")
|
|
|
+
|
|
|
+ configBucketFile := GetConfigBucketFile()
|
|
|
+
|
|
|
+ if configBucketFile != "kc-test-bucket" {
|
|
|
+ t.Errorf("Expected config bucket file to be 'kc-test-bucket', got '%s'", configBucketFile)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test config bucket file with single", func(t *testing.T) {
|
|
|
+ t.Setenv(ConfigBucketEnvVar, "test-bucket")
|
|
|
+
|
|
|
+ configBucketFile := GetConfigBucketFile()
|
|
|
+
|
|
|
+ if configBucketFile != "test-bucket" {
|
|
|
+ t.Errorf("Expected config bucket file to be 'test-bucket', got '%s'", configBucketFile)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("test config bucket file with both", func(t *testing.T) {
|
|
|
+ configBucketFile := GetConfigBucketFile()
|
|
|
+
|
|
|
+ if configBucketFile != "" {
|
|
|
+ t.Errorf("Expected config bucket file to be '', got '%s'", configBucketFile)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+}
|