github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/provider/gcp_provider_test.go (about) 1 package provider 2 3 import ( 4 "testing" 5 6 "github.com/kyma-project/kyma-environment-broker/internal" 7 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestGcpTrialInput_ApplyParametersWithRegion(t *testing.T) { 12 // given 13 svc := GcpTrialInput{ 14 PlatformRegionMapping: map[string]string{ 15 "cf-eu": "europe", 16 }, 17 } 18 19 // when 20 t.Run("use platform region mapping", func(t *testing.T) { 21 // given 22 input := svc.Defaults() 23 24 // when 25 svc.ApplyParameters(input, internal.ProvisioningParameters{ 26 PlatformRegion: "cf-eu", 27 }) 28 29 //then 30 assert.Equal(t, "europe-west3", input.GardenerConfig.Region) 31 }) 32 33 // when 34 t.Run("use customer mapping", func(t *testing.T) { 35 // given 36 input := svc.Defaults() 37 us := "us" 38 39 // when 40 svc.ApplyParameters(input, internal.ProvisioningParameters{ 41 PlatformRegion: "cf-eu", 42 Parameters: internal.ProvisioningParametersDTO{ 43 Region: &us, 44 }, 45 }) 46 47 //then 48 assert.Equal(t, "us-central1", input.GardenerConfig.Region) 49 }) 50 51 // when 52 t.Run("use default region", func(t *testing.T) { 53 // given 54 input := svc.Defaults() 55 56 // when 57 svc.ApplyParameters(input, internal.ProvisioningParameters{}) 58 59 //then 60 assert.Equal(t, "europe-west3", input.GardenerConfig.Region) 61 }) 62 63 // when 64 t.Run("use default region for not defined mapping", func(t *testing.T) { 65 // given 66 input := svc.Defaults() 67 68 // when 69 svc.ApplyParameters(input, internal.ProvisioningParameters{ 70 PlatformRegion: "cf-southamerica", 71 }) 72 73 //then 74 assert.Equal(t, "europe-west3", input.GardenerConfig.Region) 75 }) 76 } 77 78 func TestGcpInput_SingleZone_ApplyParameters(t *testing.T) { 79 // given 80 svc := GcpInput{} 81 82 // when 83 t.Run("zones with default region", func(t *testing.T) { 84 // given 85 input := svc.Defaults() 86 87 // when 88 svc.ApplyParameters(input, internal.ProvisioningParameters{ 89 Parameters: internal.ProvisioningParametersDTO{}, 90 }) 91 92 // then 93 assert.Equal(t, "europe-west3", input.GardenerConfig.Region) 94 assert.Len(t, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones, 1) 95 assert.Subset(t, []string{"europe-west3-a", "europe-west3-b", "europe-west3-c"}, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones) 96 }) 97 98 // when 99 t.Run("zones with specified region", func(t *testing.T) { 100 // given 101 input := svc.Defaults() 102 103 // when 104 svc.ApplyParameters(input, internal.ProvisioningParameters{ 105 Parameters: internal.ProvisioningParametersDTO{ 106 Region: ptr.String("us-central1"), 107 }, 108 }) 109 110 // then 111 assert.Len(t, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones, 1) 112 assert.Subset(t, []string{"us-central1-a", "us-central1-b", "us-central1-c"}, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones) 113 }) 114 } 115 116 func TestGcpInput_MultiZone_ApplyParameters(t *testing.T) { 117 // given 118 svc := GcpInput{ 119 MultiZone: true, 120 ControlPlaneFailureTolerance: "zone", 121 } 122 123 // when 124 t.Run("zones with default region", func(t *testing.T) { 125 // given 126 input := svc.Defaults() 127 128 // when 129 svc.ApplyParameters(input, internal.ProvisioningParameters{ 130 Parameters: internal.ProvisioningParametersDTO{}, 131 }) 132 133 // then 134 assert.Equal(t, "europe-west3", input.GardenerConfig.Region) 135 assert.Len(t, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones, 3) 136 assert.Subset(t, []string{"europe-west3-a", "europe-west3-b", "europe-west3-c"}, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones) 137 assert.Equal(t, "zone", *input.GardenerConfig.ControlPlaneFailureTolerance) 138 }) 139 140 // when 141 t.Run("zones with specified region", func(t *testing.T) { 142 // given 143 input := svc.Defaults() 144 145 // when 146 svc.ApplyParameters(input, internal.ProvisioningParameters{ 147 Parameters: internal.ProvisioningParametersDTO{ 148 Region: ptr.String("us-central1"), 149 }, 150 }) 151 152 // then 153 assert.Len(t, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones, 3) 154 assert.Subset(t, []string{"us-central1-a", "us-central1-b", "us-central1-c"}, input.GardenerConfig.ProviderSpecificConfig.GcpConfig.Zones) 155 assert.Equal(t, "zone", *input.GardenerConfig.ControlPlaneFailureTolerance) 156 }) 157 }