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

     1  package provisioning
     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/fixture"
     8  	"github.com/pivotal-cf/brokerapi/v8/domain"
     9  	"github.com/sirupsen/logrus"
    10  	"github.com/stretchr/testify/assert"
    11  
    12  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    13  )
    14  
    15  func TestStartStep_RunIfDeprovisioningInProgress(t *testing.T) {
    16  	// given
    17  	st := storage.NewMemoryStorage()
    18  	step := NewStartStep(st.Operations(), st.Instances())
    19  	dOp := fixture.FixDeprovisioningOperation("d-op-id", "instance-id")
    20  	dOp.State = domain.InProgress
    21  	dOp.Temporary = true
    22  	pOp := fixture.FixProvisioningOperation("p-op-id", "instance-id")
    23  	pOp.State = orchestration.Pending
    24  	inst := fixture.FixInstance("instance-id")
    25  
    26  	st.Instances().Insert(inst)
    27  	st.Operations().InsertDeprovisioningOperation(dOp)
    28  	st.Operations().InsertOperation(pOp)
    29  
    30  	// when
    31  	operation, retry, err := step.Run(pOp, logrus.New())
    32  
    33  	// then
    34  	assert.Equal(t, domain.LastOperationState(orchestration.Pending), operation.State)
    35  	assert.NoError(t, err)
    36  	assert.NotZero(t, retry)
    37  }
    38  
    39  func TestStartStep_RunIfDeprovisioningDone(t *testing.T) {
    40  	// given
    41  	st := storage.NewMemoryStorage()
    42  	step := NewStartStep(st.Operations(), st.Instances())
    43  	dOp := fixture.FixDeprovisioningOperation("d-op-id", "instance-id")
    44  	dOp.State = domain.Succeeded
    45  	dOp.Temporary = true
    46  	pOp := fixture.FixProvisioningOperation("p-op-id", "instance-id")
    47  	pOp.State = orchestration.Pending
    48  	inst := fixture.FixInstance("instance-id")
    49  
    50  	st.Instances().Insert(inst)
    51  	st.Operations().InsertDeprovisioningOperation(dOp)
    52  	st.Operations().InsertOperation(pOp)
    53  
    54  	// when
    55  	operation, retry, err := step.Run(pOp, logrus.New())
    56  
    57  	// then
    58  	assert.Equal(t, domain.InProgress, operation.State)
    59  	assert.NoError(t, err)
    60  	assert.Zero(t, retry)
    61  	storedOp, err := st.Operations().GetOperationByID("p-op-id")
    62  	assert.NoError(t, err)
    63  	assert.Equal(t, domain.InProgress, storedOp.State)
    64  }