github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/update/check_step_test.go (about) 1 package update 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 8 "github.com/kyma-project/kyma-environment-broker/internal" 9 "github.com/kyma-project/kyma-environment-broker/internal/broker" 10 "github.com/kyma-project/kyma-environment-broker/internal/provisioner" 11 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 12 "github.com/kyma-project/kyma-environment-broker/internal/storage" 13 "github.com/pivotal-cf/brokerapi/v8/domain" 14 "github.com/sirupsen/logrus" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 const ( 19 statusProvisionerOperationID = "194ae524-5343-489b-b05a-296be593e6cf" 20 statusRuntimeID = "runtime-id" 21 ) 22 23 func TestCheckRuntimeStep_RunProvisioningSucceeded(t *testing.T) { 24 for _, tc := range []struct { 25 name string 26 provisionerStatus gqlschema.OperationState 27 expectedRepeat bool 28 }{ 29 { 30 name: "In Progress", 31 provisionerStatus: gqlschema.OperationStateInProgress, 32 expectedRepeat: true, 33 }, 34 { 35 name: "Succeeded", 36 provisionerStatus: gqlschema.OperationStateSucceeded, 37 expectedRepeat: false, 38 }, 39 } { 40 t.Run(tc.name, func(t *testing.T) { 41 // given 42 provisionerClient := provisioner.NewFakeClient() 43 provisionerClient.SetOperation(statusProvisionerOperationID, gqlschema.OperationStatus{ 44 ID: ptr.String(statusProvisionerOperationID), 45 Operation: gqlschema.OperationTypeProvision, 46 State: tc.provisionerStatus, 47 Message: nil, 48 RuntimeID: ptr.String(statusRuntimeID), 49 }) 50 st := storage.NewMemoryStorage() 51 operation := fixOperationRuntimeStatus(broker.GCPPlanID) 52 operation.RuntimeID = statusRuntimeID 53 err := st.Operations().InsertOperation(operation) 54 assert.NoError(t, err) 55 56 step := NewCheckStep(st.Operations(), provisionerClient, 1*time.Second) 57 58 // when 59 operation, repeat, err := step.Run(operation, logrus.New()) 60 61 // then 62 assert.NoError(t, err) 63 assert.Equal(t, tc.expectedRepeat, repeat > 0) 64 assert.Equal(t, domain.InProgress, operation.State) 65 }) 66 } 67 } 68 69 func fixOperationRuntimeStatus(id string) internal.Operation { 70 return internal.Operation{ 71 ID: id, 72 CreatedAt: time.Now(), 73 UpdatedAt: time.Now(), 74 ProvisionerOperationID: statusProvisionerOperationID, 75 State: domain.InProgress, 76 UpdatingParameters: internal.UpdatingParametersDTO{}, 77 InputCreator: nil, 78 } 79 }