github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/resources/configmaps/configmap_test.go (about) 1 // Copyright (C) 2020, 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 configmaps 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 vmcontrollerv1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1" 11 ) 12 13 func TestVMONilConfigmap(t *testing.T) { 14 vmo := &vmcontrollerv1.VerrazzanoMonitoringInstance{} 15 configmap := NewConfig(vmo, "nilconfigmap", nil) 16 assert.Equal(t, "nilconfigmap", configmap.Name, "checking configmap data as nil") 17 } 18 19 func TestVMOEmptyConfigmap(t *testing.T) { 20 vmo := &vmcontrollerv1.VerrazzanoMonitoringInstance{} 21 configmap := NewConfig(vmo, "emptyconfigmap", map[string]string{}) 22 assert.Equal(t, "emptyconfigmap", configmap.Name, "checking configmap with empty data") 23 } 24 25 func TestVMOConfigmap(t *testing.T) { 26 vmo := &vmcontrollerv1.VerrazzanoMonitoringInstance{} 27 configmap := NewConfig(vmo, "testconfigmap", map[string]string{"key1": "value1", "key2": "value2"}) 28 assert.Equal(t, 2, len(configmap.Data), "Length of configmap data") 29 } 30 31 func TestVMOWithCascadingDelete(t *testing.T) { 32 // Without CascadingDelete 33 vmo := &vmcontrollerv1.VerrazzanoMonitoringInstance{} 34 vmo.Spec.CascadingDelete = true 35 configmap := NewConfig(vmo, "testconfigmap", map[string]string{"key1": "value1", "key2": "value2"}) 36 assert.Equal(t, 1, len(configmap.ObjectMeta.OwnerReferences), "OwnerReferences is not set with CascadingDelete true") 37 38 // Without CascadingDelete 39 vmo.Spec.CascadingDelete = false 40 configmap = NewConfig(vmo, "testconfigmap", map[string]string{"key1": "value1", "key2": "value2"}) 41 assert.Equal(t, 0, len(configmap.ObjectMeta.OwnerReferences), "OwnerReferences is set even with CascadingDelete false") 42 }