[trivial] goimports run
@@ -2,6 +2,8 @@ package shootOperations
import (
"fmt"
+ "os"
+ "strings"
"testing"
"github.com/gardener/gardener/pkg/apis/garden/v1beta1"
@@ -156,3 +158,55 @@ func TestFillSpecWK8sVer_IfCloudProfileIsntAvailable_Fail(t *testing.T) {
}
}
+func TestFillSpecFromEnv(t *testing.T) {
+ shoot := DefaultAwsConfig()
+ shoot.Spec.Maintenance = nil
+
+ env := map[string]string{
+ ENVDnsDomainSuffix: "fooDNS",
+ ENVAwsCloudProfile: "awsCloudProfile",
+ ENVAwsMaintenanceAutoupdate: "false",
+ ENVAwsMaintenanceAutoUpdateBegin: "100000+0100",
+ ENVAwsMaintenanceAutoUpdateEnd: "120000+0100",
+ }
+
+ oldEnv := make(map[string]string, len(env))
+ for k := range env {
+ if v, exists := os.LookupEnv(k); exists {
+ oldEnv[k] = v
+ }
+ }
+ resetEnv := func() {
+ for k := range env {
+ if oldVal, existedBefore := oldEnv[k]; existedBefore {
+ os.Setenv(k, oldVal)
+ } else {
+ os.Unsetenv(k)
+ }
+ }
+ }
+ defer resetEnv()
+
+ for k, newVal := range env {
+ os.Setenv(k, newVal)
+ }
+
+ fillSpecFromEnv(shoot)
+
+ if !strings.HasSuffix(*shoot.Spec.DNS.Domain, env[ENVDnsDomainSuffix]) {
+ t.Fatalf("dns domain wasn't used from env. have: %s", *shoot.Spec.DNS.Domain)
+ }
+ if shoot.Spec.Cloud.Profile != env[ENVAwsCloudProfile] {
+ t.Fatalf("cloud profile mismatch. want: %s, have: %s", env["AwsCloudProfile"], shoot.Spec.Cloud.Profile)
+ }
+
+ if shoot.Spec.Maintenance.AutoUpdate.KubernetesVersion == true {
+ t.Fatal("autoupdate of maintenance kubernetes version should be false")
+ }
+ if shoot.Spec.Maintenance.TimeWindow.Begin != env[ENVAwsMaintenanceAutoUpdateBegin] {
+ t.Fatal("time window begin mismatch")
+ }
+ if shoot.Spec.Maintenance.TimeWindow.End != env[ENVAwsMaintenanceAutoUpdateEnd] {
+ t.Fatal("time window end mismatch")
+ }
+}
