github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/initialisation_test.go (about) 1 package provisioning 2 3 import ( 4 "testing" 5 "time" 6 7 automock2 "github.com/kyma-project/kyma-environment-broker/internal/process/input/automock" 8 "github.com/sirupsen/logrus" 9 "github.com/stretchr/testify/mock" 10 11 "github.com/kyma-project/kyma-environment-broker/internal" 12 "github.com/kyma-project/kyma-environment-broker/internal/avs" 13 "github.com/kyma-project/kyma-environment-broker/internal/broker" 14 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 15 "github.com/kyma-project/kyma-environment-broker/internal/process/provisioning/automock" 16 "github.com/kyma-project/kyma-environment-broker/internal/storage" 17 "github.com/pivotal-cf/brokerapi/v8/domain" 18 "github.com/stretchr/testify/assert" 19 ) 20 21 const ( 22 statusOperationID = "17f3ddba-1132-466d-a3c5-920f544d7ea6" 23 statusInstanceID = "9d75a545-2e1e-4786-abd8-a37b14e185b9" 24 statusRuntimeID = "ef4e3210-652c-453e-8015-bba1c1cd1e1c" 25 statusGlobalAccountID = "abf73c71-a653-4951-b9c2-a26d6c2cccbd" 26 statusProvisionerOperationID = "e04de524-53b3-4890-b05a-296be393e4ba" 27 28 dashboardURL = "http://runtime.com" 29 fixAvsEvaluationInternalId = int64(1234) 30 ) 31 32 func TestInitialisationStep_Run(t *testing.T) { 33 // given 34 st := storage.NewMemoryStorage() 35 operation := fixOperationRuntimeStatus(broker.GCPPlanID, internal.GCP) 36 st.Operations().InsertOperation(operation) 37 st.Instances().Insert(fixture.FixInstance(operation.InstanceID)) 38 rvc := &automock.RuntimeVersionConfiguratorForProvisioning{} 39 v := &internal.RuntimeVersionData{ 40 Version: "1.21.0", 41 Origin: internal.Defaults, 42 } 43 rvc.On("ForProvisioning", mock.Anything).Return(v, nil) 44 ri := &simpleInputCreator{ 45 provider: internal.GCP, 46 config: &internal.ConfigForPlan{ 47 KymaTemplate: "kyma-template", 48 }, 49 } 50 builder := &automock2.CreatorForPlan{} 51 builder.On("CreateProvisionInput", operation.ProvisioningParameters, *v).Return(ri, nil) 52 53 step := NewInitialisationStep(st.Operations(), st.Instances(), builder, rvc) 54 55 // when 56 op, retry, err := step.Run(operation, logrus.New()) 57 58 // then 59 assert.NoError(t, err) 60 assert.Zero(t, retry) 61 assert.Equal(t, *v, op.RuntimeVersion) 62 assert.Equal(t, ri, op.InputCreator) 63 64 inst, _ := st.Instances().GetByID(operation.InstanceID) 65 // make sure the provider is saved into the instance 66 assert.Equal(t, internal.GCP, inst.Provider) 67 } 68 69 func fixOperationRuntimeStatus(planId string, provider internal.CloudProvider) internal.Operation { 70 provisioningOperation := fixture.FixProvisioningOperationWithProvider(statusOperationID, statusInstanceID, provider) 71 provisioningOperation.State = domain.InProgress 72 provisioningOperation.ProvisionerOperationID = statusProvisionerOperationID 73 provisioningOperation.InstanceDetails.RuntimeID = runtimeID 74 provisioningOperation.ProvisioningParameters.PlanID = planId 75 provisioningOperation.ProvisioningParameters.ErsContext.GlobalAccountID = statusGlobalAccountID 76 provisioningOperation.RuntimeVersion = internal.RuntimeVersionData{} 77 78 return provisioningOperation 79 } 80 81 func fixOperationRuntimeStatusWithProvider(planId string, provider internal.CloudProvider) internal.Operation { 82 provisioningOperation := fixture.FixProvisioningOperationWithProvider(statusOperationID, statusInstanceID, provider) 83 provisioningOperation.State = "" 84 provisioningOperation.ProvisionerOperationID = statusProvisionerOperationID 85 provisioningOperation.ProvisioningParameters.PlanID = planId 86 provisioningOperation.ProvisioningParameters.ErsContext.GlobalAccountID = statusGlobalAccountID 87 provisioningOperation.ProvisioningParameters.Parameters.Provider = &provider 88 89 return provisioningOperation 90 } 91 92 func fixInstanceRuntimeStatus() internal.Instance { 93 instance := fixture.FixInstance(statusInstanceID) 94 instance.RuntimeID = statusRuntimeID 95 instance.DashboardURL = dashboardURL 96 instance.GlobalAccountID = statusGlobalAccountID 97 98 return instance 99 } 100 101 func fixAvsEvaluation() *avs.BasicEvaluationCreateResponse { 102 return &avs.BasicEvaluationCreateResponse{ 103 DefinitionType: "av", 104 Name: "fake-internal-eval", 105 Description: "", 106 Service: "", 107 URL: "", 108 CheckType: "", 109 Interval: 180, 110 TesterAccessId: int64(999), 111 Timeout: 30000, 112 ReadOnly: false, 113 ContentCheck: "", 114 ContentCheckType: "", 115 Threshold: 30000, 116 GroupId: int64(4321), 117 Visibility: "PUBLIC", 118 DateCreated: time.Now().Unix(), 119 DateChanged: time.Now().Unix(), 120 Owner: "johndoe@xyz.corp", 121 Status: "ACTIVE", 122 Alerts: nil, 123 Tags: []*avs.Tag{ 124 { 125 Content: "already-exist-tag", 126 TagClassId: 123456, 127 TagClassName: "already-exist-tag-classname", 128 }, 129 }, 130 Id: fixAvsEvaluationInternalId, 131 LegacyCheckId: fixAvsEvaluationInternalId, 132 InternalInterval: 60, 133 AuthType: "AUTH_NONE", 134 IndividualOutageEventsOnly: false, 135 IdOnTester: "", 136 } 137 }