github.com/verrazzano/verrazzano@v1.7.0/platform-operator/internal/config/config_test.go (about)

     1  // Copyright (c) 2020, 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package config
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"k8s.io/apimachinery/pkg/runtime/schema"
    11  )
    12  
    13  // TestConfigDefaults tests the config default values
    14  // GIVEN a new OperatorConfig object
    15  //
    16  //	WHEN I call New
    17  //	THEN the value returned are correct defaults
    18  func TestConfigDefaults(t *testing.T) {
    19  	asserts := assert.New(t)
    20  	conf := Get()
    21  	asserts.Equal("/etc/webhook/certs", conf.CertDir, "CertDir is incorrect")
    22  	asserts.False(conf.RunWebhookInit, "RunWebhookInit is incorrect")
    23  	asserts.False(conf.RunWebhooks, "RunWebhooks is correct")
    24  	asserts.Equal(conf.DryRun, false, "Default dry run is false")
    25  	asserts.False(conf.LeaderElectionEnabled, "LeaderElectionEnabled is incorrect")
    26  	asserts.Equal(":8080", conf.MetricsAddr, "MetricsAddr is incorrect")
    27  	asserts.Equal(int64(60), conf.HealthCheckPeriodSeconds, "Default health check period is correct")
    28  	asserts.Equal(int64(60), conf.MySQLCheckPeriodSeconds, "Default MySQL check period is correct")
    29  	asserts.Equal(int64(120), conf.MySQLRepairTimeoutSeconds, "Default MySQL repair timeout is correct")
    30  	asserts.True(conf.VersionCheckEnabled, "VersionCheckEnabled is incorrect")
    31  	asserts.False(conf.RunWebhooks, "RunWebhooks is incorrect")
    32  	asserts.False(conf.ResourceRequirementsValidation, "ResourceRequirementsValidation default value is incorrect")
    33  	asserts.True(conf.WebhookValidationEnabled, "WebhookValidationEnabled is incorrect")
    34  	asserts.False(conf.CloudCredentialWatchEnabled, "CloudCredentialWatchEnabled is incorrect")
    35  	asserts.Equal(conf.VerrazzanoRootDir, "/verrazzano", "VerrazzanoRootDir is incorrect")
    36  	asserts.Equal("/verrazzano/platform-operator/helm_config", GetHelmConfigDir(), "GetHelmConfigDir() is incorrect")
    37  	asserts.Equal("/verrazzano/platform-operator/helm_config/charts", GetHelmChartsDir(), "GetHelmChartsDir() is incorrect")
    38  	asserts.Equal("/verrazzano/platform-operator/helm_config/charts/verrazzano-monitoring-operator", GetHelmVMOChartsDir(), "GetHelmVmoChartsDir() is incorrect")
    39  	asserts.Equal("/verrazzano/platform-operator/helm_config/charts/verrazzano-application-operator", GetHelmAppOpChartsDir(), "GetHelmAppOpChartsDir() is incorrect")
    40  	asserts.Equal("/verrazzano/platform-operator/helm_config/charts/verrazzano-cluster-operator", GetHelmClusterOpChartsDir(), "GetHelmClusterOpChartsDir() is incorrect")
    41  	asserts.Equal("/verrazzano/platform-operator/thirdparty/charts/kiali-server", GetHelmKialiChartsDir(), "GetHelmKialiChartsDir() is incorrect")
    42  	asserts.Equal("/verrazzano/platform-operator/thirdparty/charts/oam-kubernetes-runtime", GetHelmOamChartsDir(), "GetHelmOamChartsDir() is incorrect")
    43  	asserts.Equal("/verrazzano/platform-operator/helm_config/overrides", GetHelmOverridesDir(), "GetHelmOverridesDir() is incorrect")
    44  	asserts.Equal("/verrazzano/platform-operator/scripts/install", GetInstallDir(), "GetInstallDir() is incorrect")
    45  	asserts.Equal("/verrazzano/platform-operator", GetPlatformDir(), "GetPlatformDir() is incorrect")
    46  	asserts.Equal("/verrazzano/platform-operator/thirdparty/charts", GetThirdPartyDir(), "GetThirdPartyDir() is incorrect")
    47  	asserts.Equal("/verrazzano/platform-operator/manifests/profiles", GetProfilesDir(), "GetProfilesDir() is correct")
    48  	asserts.Equal("/verrazzano/platform-operator/helm_config", GetHelmConfigDir(), "GetHelmConfigDir() is correct")
    49  	asserts.Equal("/verrazzano/platform-operator/verrazzano-bom.json", GetDefaultBOMFilePath(), "GetDefaultBOMFilePath() is correct")
    50  	asserts.Equal("/verrazzano/platform-operator/experimental/manifests/integration-charts", GetIntegrationChartsDir(), "GetIntegrationChartsDir() is correct")
    51  	asserts.Equal("/verrazzano/platform-operator/manifests/catalog/catalog.yaml", GetCatalogPath(), "GetCatalogPath() is correct")
    52  }
    53  
    54  // TestSetConfig tests setting config values
    55  // GIVEN an OperatorConfig object with non-default values
    56  //
    57  //		WHEN I call Set
    58  //		THEN Get returns the correct values
    59  //	    Able to override variables
    60  func TestSetConfig(t *testing.T) {
    61  	asserts := assert.New(t)
    62  	vzsystemNamespace := []string{"verrazzano-system", "verrazzano-monitoring", "verrazzano-ingress-nginx", "keycloak"}
    63  	vznonsystemNamespace := []string{"coherence-operator", "oam-kubernetes-runtime", "verrazzano-application-operator", "verrazzano-cluster-operator"}
    64  	TestHelmConfigDir = "/etc/verrazzano/helm_config"
    65  	TestProfilesDir = "/etc/verrazzano/profile"
    66  	bomFilePathOverride = "/etc/verrazzano/bom.json"
    67  	groupVersion := schema.GroupVersion{
    68  		Group:   "test",
    69  		Version: "1.0",
    70  	}
    71  	Set(OperatorConfig{
    72  		CertDir:                        "/test/certs",
    73  		RunWebhookInit:                 true,
    74  		MetricsAddr:                    "1111",
    75  		LeaderElectionEnabled:          true,
    76  		VersionCheckEnabled:            false,
    77  		RunWebhooks:                    true,
    78  		ResourceRequirementsValidation: true,
    79  		WebhookValidationEnabled:       false,
    80  		CloudCredentialWatchEnabled:    false,
    81  		VerrazzanoRootDir:              "/root",
    82  		HealthCheckPeriodSeconds:       int64(0),
    83  		MySQLCheckPeriodSeconds:        int64(0),
    84  		DryRun:                         true,
    85  	})
    86  
    87  	conf := Get()
    88  	SetDefaultBomFilePath("/etc/bom.json")
    89  	defer SetDefaultBomFilePath("")
    90  	asserts.Equal("/test/certs", conf.CertDir, "CertDir is incorrect")
    91  	asserts.True(conf.RunWebhookInit, "RunWebhookInit is incorrect")
    92  	asserts.True(conf.LeaderElectionEnabled, "LeaderElectionEnabled is incorrect")
    93  	asserts.Equal("1111", conf.MetricsAddr, "MetricsAddr is incorrect")
    94  	asserts.False(conf.VersionCheckEnabled, "VersionCheckEnabled is incorrect")
    95  	asserts.True(conf.RunWebhooks, "RunWebhooks is incorrect")
    96  	asserts.True(conf.ResourceRequirementsValidation, "ResourceRequirementsValidation default value is incorrect")
    97  	asserts.False(conf.WebhookValidationEnabled, "WebhookValidationEnabled is incorrect")
    98  	asserts.False(conf.CloudCredentialWatchEnabled, "CloudCredentialWatchEnabled is incorrect")
    99  	asserts.Equal(conf.DryRun, true, "Default dry run is true")
   100  	asserts.Equal("/root", conf.VerrazzanoRootDir, "VerrazzanoRootDir is incorrect")
   101  	asserts.Equal("/etc/verrazzano/helm_config", GetHelmConfigDir(), "GetHelmConfigDir() is incorrect")
   102  	asserts.Equal("/etc/verrazzano/helm_config/charts", GetHelmChartsDir(), "GetHelmChartsDir() is incorrect")
   103  	asserts.Equal("/etc/verrazzano/helm_config/charts/verrazzano-monitoring-operator", GetHelmVMOChartsDir(), "GetHelmVmoChartsDir() is incorrect")
   104  	asserts.Equal("/etc/verrazzano/helm_config/charts/verrazzano-application-operator", GetHelmAppOpChartsDir(), "GetHelmAppOpChartsDir() is incorrect")
   105  	asserts.Equal("/etc/verrazzano/helm_config/charts/verrazzano-cluster-operator", GetHelmClusterOpChartsDir(), "GetHelmClusterOpChartsDir() is incorrect")
   106  	asserts.Equal("/etc/verrazzano/helm_config/overrides", GetHelmOverridesDir(), "GetHelmOverridesDir() is incorrect")
   107  	asserts.Equal("/root/platform-operator/scripts/install", GetInstallDir(), "GetInstallDir() is incorrect")
   108  	asserts.Equal("/root/platform-operator", GetPlatformDir(), "GetPlatformDir() is incorrect")
   109  	asserts.Equal("/root/platform-operator/thirdparty/charts", GetThirdPartyDir(), "GetThirdPartyDir() is incorrect")
   110  	asserts.Equal("/etc/verrazzano/helm_config/charts/prometheus-community/kube-prometheus-stack", GetHelmPromOpChartsDir(), "GetHelmPromOpChartsDir() is incorrect")
   111  	asserts.Equal("/etc/verrazzano/helm_config/charts/kiali-server", GetHelmKialiChartsDir(), "GetHelmKialiChartsDir() is incorrect")
   112  	asserts.Equal("/etc/verrazzano/helm_config/charts/oam-kubernetes-runtime", GetHelmOamChartsDir(), "GetHelmOamChartsDir() is incorrect")
   113  	asserts.Equal("/root/platform-operator/thirdparty/manifests", GetThirdPartyManifestsDir(), "GetThirdPartyManifestsDir is incorrect")
   114  	asserts.Equal("/etc/verrazzano/profile", GetProfilesDir(), "GetProfilesDir() is incorrect")
   115  	asserts.Equal("/etc/bom.json", GetDefaultBOMFilePath(), "GetDefaultBOMFilePath() is incorrect")
   116  	asserts.Equal(vzsystemNamespace, GetInjectedSystemNamespaces(), "GetInjectedSystemNamespaces() is incorrect")
   117  	asserts.Equal(vznonsystemNamespace, GetNoInjectionComponents(), "GetNoInjectionComponents() is incorrect")
   118  	asserts.Equal("/etc/verrazzano/profile/1.0/dev.yaml", GetProfile(groupVersion, "dev"), "GetProfile() is correct")
   119  }