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

     1  package provisioning
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/kyma-project/kyma-environment-broker/internal/fixture"
     8  
     9  	"github.com/kyma-project/kyma-environment-broker/internal"
    10  	"github.com/kyma-project/kyma-environment-broker/internal/broker"
    11  	"github.com/kyma-project/kyma-environment-broker/internal/process/provisioning/automock"
    12  	"github.com/sirupsen/logrus"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestEnableForTrialPlanStepShouldSkip(t *testing.T) {
    17  	// Given
    18  	log := logrus.New()
    19  	wantSkipTime := time.Duration(0)
    20  	wantOperation := fixOperationWithPlanID("non-trial-plan")
    21  
    22  	mockStep := new(automock.Step)
    23  	mockStep.On("Name").Return("Test")
    24  	enableStep := NewEnableForTrialPlanStep(mockStep)
    25  
    26  	// When
    27  	gotOperation, gotSkipTime, gotErr := enableStep.Run(wantOperation, log)
    28  
    29  	// Then
    30  	mockStep.AssertExpectations(t)
    31  	assert.Nil(t, gotErr)
    32  	assert.Equal(t, wantSkipTime, gotSkipTime)
    33  	assert.Equal(t, wantOperation, gotOperation)
    34  }
    35  
    36  func TestEnableForTrialPlanStepShouldNotSkip(t *testing.T) {
    37  	// Given
    38  	log := logrus.New()
    39  	wantSkipTime := time.Duration(10)
    40  	givenOperation1 := fixOperationWithPlanID(broker.TrialPlanID)
    41  	wantOperation2 := fixOperationWithPlanID("operation2")
    42  
    43  	mockStep := new(automock.Step)
    44  	mockStep.On("Run", givenOperation1, log).Return(wantOperation2, wantSkipTime, nil)
    45  	skipStep := NewEnableForTrialPlanStep(mockStep)
    46  
    47  	// When
    48  	gotOperation, gotSkipTime, gotErr := skipStep.Run(givenOperation1, log)
    49  
    50  	// Then
    51  	mockStep.AssertExpectations(t)
    52  	assert.Nil(t, gotErr)
    53  	assert.Equal(t, wantSkipTime, gotSkipTime)
    54  	assert.Equal(t, wantOperation2, gotOperation)
    55  }
    56  
    57  func fixOperationWithPlanID(planID string) internal.Operation {
    58  	Operation := fixture.FixProvisioningOperation(operationID, instanceID)
    59  	Operation.ProvisioningParameters = fixProvisioningParametersWithPlanID(planID, "region", "")
    60  
    61  	return Operation
    62  }
    63  
    64  func fixOperationWithPlanIDAndKymaVersion(planID, version string) internal.Operation {
    65  	Operation := fixOperationWithPlanID(planID)
    66  	Operation.RuntimeVersion.Version = version
    67  
    68  	return Operation
    69  }