github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/update/initialisation_step_test.go (about) 1 package update 2 3 import ( 4 "testing" 5 6 "github.com/kyma-project/kyma-environment-broker/common/orchestration" 7 "github.com/kyma-project/kyma-environment-broker/internal" 8 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 9 "github.com/kyma-project/kyma-environment-broker/internal/process/input/automock" 10 automock2 "github.com/kyma-project/kyma-environment-broker/internal/process/update/automock" 11 "github.com/kyma-project/kyma-environment-broker/internal/storage" 12 "github.com/pivotal-cf/brokerapi/v8/domain" 13 "github.com/sirupsen/logrus" 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/mock" 16 "github.com/stretchr/testify/require" 17 ) 18 19 func TestInitialisationStep_OtherOperationIsInProgress(t *testing.T) { 20 21 for tn, tc := range map[string]struct { 22 beforeFunc func(os storage.Operations) 23 expectedRepeat bool 24 }{ 25 "in progress provisioning": { 26 beforeFunc: func(os storage.Operations) { 27 provisioningOperation := fixture.FixProvisioningOperation("p-id", "iid") 28 provisioningOperation.State = domain.InProgress 29 os.InsertOperation(provisioningOperation) 30 }, 31 expectedRepeat: true, 32 }, 33 "succeeded provisioning": { 34 beforeFunc: func(os storage.Operations) { 35 provisioningOperation := fixture.FixProvisioningOperation("p-id", "iid") 36 provisioningOperation.State = domain.Succeeded 37 os.InsertOperation(provisioningOperation) 38 }, 39 expectedRepeat: false, 40 }, 41 "in progress upgrade shoot": { 42 beforeFunc: func(os storage.Operations) { 43 op := fixture.FixUpgradeClusterOperation("op-id", "iid") 44 op.State = domain.InProgress 45 os.InsertUpgradeClusterOperation(op) 46 }, 47 expectedRepeat: true, 48 }, 49 "in progress upgrade kyma": { 50 beforeFunc: func(os storage.Operations) { 51 op := fixture.FixUpgradeKymaOperation("op-id", "iid") 52 op.State = domain.InProgress 53 os.InsertUpgradeKymaOperation(op) 54 }, 55 expectedRepeat: true, 56 }, 57 "in progress update": { 58 beforeFunc: func(os storage.Operations) { 59 op := fixture.FixUpdatingOperation("op-id", "iid") 60 op.State = domain.InProgress 61 os.InsertUpdatingOperation(op) 62 }, 63 expectedRepeat: true, 64 }, 65 "in progress deprovisioning": { 66 beforeFunc: func(os storage.Operations) { 67 op := fixture.FixDeprovisioningOperation("op-id", "iid") 68 op.State = domain.InProgress 69 os.InsertDeprovisioningOperation(op) 70 }, 71 expectedRepeat: true, 72 }, 73 } { 74 t.Run(tn, func(t *testing.T) { 75 db := storage.NewMemoryStorage() 76 os := db.Operations() 77 is := db.Instances() 78 rs := db.RuntimeStates() 79 inst := fixture.FixInstance("iid") 80 state := fixture.FixRuntimeState("op-id", "Runtime-iid", "op-id") 81 is.Insert(inst) 82 rs.Insert(state) 83 ver := &internal.RuntimeVersionData{ 84 Version: "2.4.0", 85 Origin: internal.Defaults, 86 } 87 rvc := &automock2.RuntimeVersionConfiguratorForUpdating{} 88 rvc.On("ForUpdating", 89 mock.AnythingOfType("internal.Operation")). 90 Return(ver, nil) 91 builder := &automock.CreatorForPlan{} 92 builder.On("CreateUpgradeShootInput", 93 mock.Anything, mock.AnythingOfType("internal.RuntimeVersionData")). 94 Return(&fixture.SimpleInputCreator{}, nil) 95 step := NewInitialisationStep(is, os, rvc, builder) 96 updatingOperation := fixture.FixUpdatingOperation("up-id", "iid") 97 updatingOperation.State = orchestration.Pending 98 os.InsertOperation(updatingOperation.Operation) 99 tc.beforeFunc(os) 100 101 // when 102 _, d, err := step.Run(updatingOperation.Operation, logrus.New()) 103 104 // then 105 require.NoError(t, err) 106 assert.Equal(t, tc.expectedRepeat, d != 0) 107 }) 108 } 109 }