github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/upgrade_kyma/simple_provisioner_input_creator_test.go (about) 1 package upgrade_kyma 2 3 import ( 4 "testing" 5 6 reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb" 7 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 8 "github.com/kyma-project/kyma-environment-broker/common/gardener" 9 internal "github.com/kyma-project/kyma-environment-broker/internal" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func newInputCreator() *simpleInputCreator { 15 return &simpleInputCreator{ 16 overrides: make(map[string][]*gqlschema.ConfigEntryInput, 0), 17 labels: make(map[string]string), 18 enabledComponents: []string{}, 19 } 20 } 21 22 type simpleInputCreator struct { 23 overrides map[string][]*gqlschema.ConfigEntryInput 24 labels map[string]string 25 enabledComponents []string 26 shootName *string 27 shootDomain string 28 shootDnsProviders gardener.DNSProvidersData 29 clusterName string 30 config *internal.ConfigForPlan 31 } 32 33 func (c *simpleInputCreator) EnableOptionalComponent(name string) internal.ProvisionerInputCreator { 34 c.enabledComponents = append(c.enabledComponents, name) 35 return c 36 } 37 38 func (c *simpleInputCreator) DisableOptionalComponent(name string) internal.ProvisionerInputCreator { 39 for i, cmp := range c.enabledComponents { 40 if cmp == name { 41 c.enabledComponents = append(c.enabledComponents[:i], c.enabledComponents[i+1:]...) 42 } 43 } 44 return c 45 } 46 47 func (c *simpleInputCreator) SetLabel(key, val string) internal.ProvisionerInputCreator { 48 c.labels[key] = val 49 return c 50 } 51 52 func (c *simpleInputCreator) SetClusterName(name string) internal.ProvisionerInputCreator { 53 c.clusterName = name 54 return c 55 } 56 57 func (c *simpleInputCreator) SetShootName(name string) internal.ProvisionerInputCreator { 58 c.shootName = &name 59 return c 60 } 61 62 func (c *simpleInputCreator) SetShootDomain(name string) internal.ProvisionerInputCreator { 63 c.shootDomain = name 64 return c 65 } 66 67 func (c *simpleInputCreator) SetShootDNSProviders(providers gardener.DNSProvidersData) internal.ProvisionerInputCreator { 68 c.shootDnsProviders = providers 69 return c 70 } 71 72 func (c *simpleInputCreator) SetOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 73 return c 74 } 75 76 func (c *simpleInputCreator) CreateProvisionRuntimeInput() (gqlschema.ProvisionRuntimeInput, error) { 77 return gqlschema.ProvisionRuntimeInput{}, nil 78 } 79 80 func (c *simpleInputCreator) CreateUpgradeShootInput() (gqlschema.UpgradeShootInput, error) { 81 return gqlschema.UpgradeShootInput{}, nil 82 } 83 84 func (c *simpleInputCreator) CreateUpgradeRuntimeInput() (gqlschema.UpgradeRuntimeInput, error) { 85 return gqlschema.UpgradeRuntimeInput{}, nil 86 } 87 88 func (c *simpleInputCreator) SetProvisioningParameters(params internal.ProvisioningParameters) internal.ProvisionerInputCreator { 89 return c 90 } 91 92 func (c *simpleInputCreator) AppendOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 93 c.overrides[component] = append(c.overrides[component], overrides...) 94 return c 95 } 96 97 func (c *simpleInputCreator) Configuration() *internal.ConfigForPlan { 98 return c.config 99 } 100 101 func (c *simpleInputCreator) Provider() internal.CloudProvider { 102 return internal.GCP 103 } 104 105 func (c *simpleInputCreator) AppendGlobalOverrides(overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator { 106 return c 107 } 108 109 func (c *simpleInputCreator) AssertOverride(t *testing.T, component string, cei gqlschema.ConfigEntryInput) { 110 cmpOverrides, found := c.overrides[component] 111 require.True(t, found) 112 113 for _, item := range cmpOverrides { 114 if item.Key == cei.Key { 115 assert.Equal(t, cei, *item) 116 return 117 } 118 } 119 assert.Failf(t, "Overrides assert failed", "Expected component override not found: %+v", cei) 120 } 121 122 func (c *simpleInputCreator) AssertNoOverrides(t *testing.T) { 123 assert.Empty(t, c.overrides) 124 } 125 126 func (c *simpleInputCreator) AssertLabel(t *testing.T, key, expectedValue string) { 127 value, found := c.labels[key] 128 require.True(t, found) 129 assert.Equal(t, expectedValue, value) 130 } 131 132 func (c *simpleInputCreator) AssertEnabledComponent(t *testing.T, componentName string) { 133 assert.Contains(t, c.enabledComponents, componentName) 134 } 135 136 func (c *simpleInputCreator) CreateClusterConfiguration() (reconcilerApi.Cluster, error) { 137 return reconcilerApi.Cluster{}, nil 138 } 139 140 func (c *simpleInputCreator) CreateProvisionClusterInput() (gqlschema.ProvisionRuntimeInput, error) { 141 return gqlschema.ProvisionRuntimeInput{}, nil 142 } 143 144 func (c *simpleInputCreator) SetKubeconfig(_ string) internal.ProvisionerInputCreator { 145 return c 146 } 147 148 func (c *simpleInputCreator) SetRuntimeID(_ string) internal.ProvisionerInputCreator { 149 return c 150 } 151 152 func (c *simpleInputCreator) SetInstanceID(_ string) internal.ProvisionerInputCreator { 153 return c 154 } 155 156 func (c *simpleInputCreator) SetOIDCLastValues(oidcConfig gqlschema.OIDCConfigInput) internal.ProvisionerInputCreator { 157 return c 158 }