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

     1  package update
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema"
     7  	"github.com/kyma-project/kyma-environment-broker/internal"
     8  	"github.com/kyma-project/kyma-environment-broker/internal/broker"
     9  	"github.com/kyma-project/kyma-environment-broker/internal/fixture"
    10  	"github.com/kyma-project/kyma-environment-broker/internal/process/input"
    11  	inputAutomock "github.com/kyma-project/kyma-environment-broker/internal/process/input/automock"
    12  	"github.com/kyma-project/kyma-environment-broker/internal/provisioner"
    13  	"github.com/kyma-project/kyma-environment-broker/internal/runtime"
    14  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    15  	"github.com/sirupsen/logrus"
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/mock"
    18  	"github.com/stretchr/testify/require"
    19  )
    20  
    21  func TestUpgradeShootStep_Run(t *testing.T) {
    22  	// given
    23  	memoryStorage := storage.NewMemoryStorage()
    24  	os := memoryStorage.Operations()
    25  	rs := memoryStorage.RuntimeStates()
    26  	cli := provisioner.NewFakeClient()
    27  	step := NewUpgradeShootStep(os, rs, cli)
    28  	operation := fixture.FixUpdatingOperation("op-id", "inst-id")
    29  	operation.RuntimeID = "runtime-id"
    30  	operation.ProvisionerOperationID = ""
    31  	operation.ProvisioningParameters.ErsContext.UserID = "test-user-id"
    32  	operation.ProvisioningParameters.Parameters.OIDC = &internal.OIDCConfigDTO{
    33  		ClientID:       "client-id",
    34  		GroupsClaim:    "groups",
    35  		IssuerURL:      "https://issuer.url",
    36  		SigningAlgs:    []string{"RSA256"},
    37  		UsernameClaim:  "sub",
    38  		UsernamePrefix: "-",
    39  	}
    40  	operation.InputCreator = fixInputCreator(t)
    41  	os.InsertOperation(operation.Operation)
    42  	runtimeState := fixture.FixRuntimeState("runtime-id", "runtime-id", "provisioning-op-1")
    43  	runtimeState.ClusterConfig.OidcConfig = &gqlschema.OIDCConfigInput{
    44  		ClientID:       "clientID",
    45  		GroupsClaim:    "groupsClaim",
    46  		IssuerURL:      "https://issuer.url",
    47  		SigningAlgs:    []string{"PS512"},
    48  		UsernameClaim:  "usernameClaim",
    49  		UsernamePrefix: "usernamePrefix",
    50  	}
    51  	rs.Insert(runtimeState)
    52  
    53  	// when
    54  	newOperation, d, err := step.Run(operation.Operation, logrus.New())
    55  
    56  	// then
    57  	require.NoError(t, err)
    58  	assert.Zero(t, d)
    59  	assert.True(t, cli.IsShootUpgraded("runtime-id"))
    60  	req, _ := cli.LastShootUpgrade("runtime-id")
    61  	disabled := false
    62  	assert.Equal(t, gqlschema.UpgradeShootInput{
    63  		GardenerConfig: &gqlschema.GardenerUpgradeInput{
    64  			OidcConfig: &gqlschema.OIDCConfigInput{
    65  				ClientID:       "client-id",
    66  				GroupsClaim:    "groups",
    67  				IssuerURL:      "https://issuer.url",
    68  				SigningAlgs:    []string{"RSA256"},
    69  				UsernameClaim:  "sub",
    70  				UsernamePrefix: "-",
    71  			},
    72  			ShootNetworkingFilterDisabled: &disabled,
    73  		},
    74  		Administrators: []string{"test-user-id"},
    75  	}, req)
    76  	assert.NotEmpty(t, newOperation.ProvisionerOperationID)
    77  }
    78  
    79  func fixInputCreator(t *testing.T) internal.ProvisionerInputCreator {
    80  	optComponentsSvc := &inputAutomock.OptionalComponentService{}
    81  
    82  	optComponentsSvc.On("ComputeComponentsToDisable", []string{}).Return([]string{})
    83  	optComponentsSvc.On("ExecuteDisablers", internal.ComponentConfigurationInputList{
    84  		{
    85  			Component:     "to-remove-component",
    86  			Namespace:     "kyma-system",
    87  			Configuration: nil,
    88  		},
    89  		{
    90  			Component:     "keb",
    91  			Namespace:     "kyma-system",
    92  			Configuration: nil,
    93  		},
    94  	}).Return(internal.ComponentConfigurationInputList{
    95  		{
    96  			Component:     "keb",
    97  			Namespace:     "kyma-system",
    98  			Configuration: nil,
    99  		},
   100  	}, nil)
   101  
   102  	componentsProvider := &inputAutomock.ComponentListProvider{}
   103  	const kymaVersion = "1.20"
   104  	defer componentsProvider.AssertExpectations(t)
   105  
   106  	configProvider := &inputAutomock.ConfigurationProvider{}
   107  	configProvider.On("ProvideForGivenVersionAndPlan",
   108  		mock.AnythingOfType("string"),
   109  		mock.AnythingOfType("string")).
   110  		Return(&internal.ConfigForPlan{
   111  			AdditionalComponents: []internal.KymaComponent{
   112  				{
   113  					Name:      "kyma-component1",
   114  					Namespace: "kyma-system",
   115  				},
   116  			},
   117  		}, nil)
   118  
   119  	const k8sVersion = "1.18"
   120  	ibf, err := input.NewInputBuilderFactory(optComponentsSvc, runtime.NewDisabledComponentsProvider(),
   121  		componentsProvider, configProvider, input.Config{
   122  			KubernetesVersion:           k8sVersion,
   123  			DefaultGardenerShootPurpose: "test",
   124  		}, kymaVersion, fixTrialRegionMapping(), fixFreemiumProviders(), fixture.FixOIDCConfigDTO())
   125  	assert.NoError(t, err)
   126  
   127  	pp := internal.ProvisioningParameters{
   128  		PlanID: broker.GCPPlanID,
   129  		Parameters: internal.ProvisioningParametersDTO{
   130  			KymaVersion: "",
   131  		},
   132  	}
   133  	ver := internal.RuntimeVersionData{
   134  		Version: kymaVersion,
   135  		Origin:  internal.Defaults,
   136  	}
   137  	creator, err := ibf.CreateUpgradeShootInput(pp, ver)
   138  	if err != nil {
   139  		t.Errorf("cannot create input creator for %q plan", broker.GCPPlanID)
   140  	}
   141  
   142  	return creator
   143  }
   144  
   145  func fixTrialRegionMapping() map[string]string {
   146  	return map[string]string{}
   147  }
   148  
   149  func fixFreemiumProviders() []string {
   150  	return []string{"azure", "aws"}
   151  }