github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/base_provision_test.go (about)

     1  package provisioning
     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  	"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  	provider          internal.CloudProvider
    28  	shootDomain       string
    29  	shootDnsProviders gardener.DNSProvidersData
    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) Configuration() *internal.ConfigForPlan {
    48  	return c.config
    49  }
    50  
    51  func (c *simpleInputCreator) Provider() internal.CloudProvider {
    52  	if c.provider != "" {
    53  		return c.provider
    54  	}
    55  	return internal.Azure
    56  }
    57  
    58  func (c *simpleInputCreator) SetLabel(key, val string) internal.ProvisionerInputCreator {
    59  	c.labels[key] = val
    60  	return c
    61  }
    62  
    63  func (c *simpleInputCreator) SetShootName(name string) internal.ProvisionerInputCreator {
    64  	c.shootName = &name
    65  	return c
    66  }
    67  
    68  func (c *simpleInputCreator) SetShootDomain(name string) internal.ProvisionerInputCreator {
    69  	c.shootDomain = name
    70  	return c
    71  }
    72  
    73  func (c *simpleInputCreator) SetShootDNSProviders(providers gardener.DNSProvidersData) internal.ProvisionerInputCreator {
    74  	c.shootDnsProviders = providers
    75  	return c
    76  }
    77  
    78  func (c *simpleInputCreator) SetOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator {
    79  	return c
    80  }
    81  
    82  func (c *simpleInputCreator) CreateProvisionRuntimeInput() (gqlschema.ProvisionRuntimeInput, error) {
    83  	return gqlschema.ProvisionRuntimeInput{}, nil
    84  }
    85  
    86  func (c *simpleInputCreator) CreateUpgradeRuntimeInput() (gqlschema.UpgradeRuntimeInput, error) {
    87  	return gqlschema.UpgradeRuntimeInput{}, nil
    88  }
    89  
    90  func (c *simpleInputCreator) CreateUpgradeShootInput() (gqlschema.UpgradeShootInput, error) {
    91  	return gqlschema.UpgradeShootInput{}, nil
    92  }
    93  
    94  func (c *simpleInputCreator) SetProvisioningParameters(params internal.ProvisioningParameters) internal.ProvisionerInputCreator {
    95  	return c
    96  }
    97  
    98  func (c *simpleInputCreator) SetKubeconfig(_ string) internal.ProvisionerInputCreator {
    99  	return c
   100  }
   101  
   102  func (c *simpleInputCreator) SetRuntimeID(_ string) internal.ProvisionerInputCreator {
   103  	return c
   104  }
   105  
   106  func (c *simpleInputCreator) SetInstanceID(_ string) internal.ProvisionerInputCreator {
   107  	return c
   108  }
   109  
   110  func (c *simpleInputCreator) SetClusterName(_ string) internal.ProvisionerInputCreator {
   111  	return c
   112  }
   113  
   114  func (c *simpleInputCreator) SetOIDCLastValues(oidcConfig gqlschema.OIDCConfigInput) internal.ProvisionerInputCreator {
   115  	return c
   116  }
   117  
   118  func (c *simpleInputCreator) AppendOverrides(component string, overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator {
   119  	c.overrides[component] = append(c.overrides[component], overrides...)
   120  	return c
   121  }
   122  
   123  func (c *simpleInputCreator) AppendGlobalOverrides(overrides []*gqlschema.ConfigEntryInput) internal.ProvisionerInputCreator {
   124  	return c
   125  }
   126  
   127  func (c *simpleInputCreator) AssertOverride(t *testing.T, component string, cei gqlschema.ConfigEntryInput) {
   128  	cmpOverrides, found := c.overrides[component]
   129  	require.True(t, found)
   130  
   131  	for _, item := range cmpOverrides {
   132  		if item.Key == cei.Key {
   133  			assert.Equal(t, cei, *item)
   134  			return
   135  		}
   136  	}
   137  	assert.Failf(t, "Overrides assert failed", "Expected component override not found: %+v", cei)
   138  }
   139  
   140  func (c *simpleInputCreator) AssertNoOverrides(t *testing.T) {
   141  	assert.Empty(t, c.overrides)
   142  }
   143  
   144  func (c *simpleInputCreator) AssertLabel(t *testing.T, key, expectedValue string) {
   145  	value, found := c.labels[key]
   146  	require.True(t, found)
   147  	assert.Equal(t, expectedValue, value)
   148  }
   149  
   150  func (c *simpleInputCreator) AssertEnabledComponent(t *testing.T, componentName string) {
   151  	assert.Contains(t, c.enabledComponents, componentName)
   152  }
   153  
   154  func (c *simpleInputCreator) CreateClusterConfiguration() (reconcilerApi.Cluster, error) {
   155  	return reconcilerApi.Cluster{}, nil
   156  }
   157  
   158  func (c *simpleInputCreator) CreateProvisionClusterInput() (gqlschema.ProvisionRuntimeInput, error) {
   159  	return gqlschema.ProvisionRuntimeInput{}, nil
   160  }