github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/skip_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/broker"
     8  	"github.com/kyma-project/kyma-environment-broker/internal/process/provisioning/automock"
     9  	"github.com/sirupsen/logrus"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestSkipForTrialPlanStepShouldSkip(t *testing.T) {
    14  	// Given
    15  	log := logrus.New()
    16  	wantSkipTime := time.Duration(0)
    17  	wantOperation := fixOperationWithPlanID(broker.TrialPlanID)
    18  
    19  	mockStep := new(automock.Step)
    20  	mockStep.On("Name").Return("Test")
    21  	skipStep := NewSkipForTrialPlanStep(mockStep)
    22  
    23  	// When
    24  	gotOperation, gotSkipTime, gotErr := skipStep.Run(wantOperation, log)
    25  
    26  	// Then
    27  	mockStep.AssertExpectations(t)
    28  	assert.Nil(t, gotErr)
    29  	assert.Equal(t, wantSkipTime, gotSkipTime)
    30  	assert.Equal(t, wantOperation, gotOperation)
    31  }
    32  
    33  func TestSkipForTrialPlanStepShouldNotSkip(t *testing.T) {
    34  	// Given
    35  	log := logrus.New()
    36  	wantSkipTime := time.Duration(10)
    37  	givenOperation1 := fixOperationWithPlanID("operation1")
    38  	wantOperation2 := fixOperationWithPlanID("operation2")
    39  
    40  	mockStep := new(automock.Step)
    41  	mockStep.On("Run", givenOperation1, log).Return(wantOperation2, wantSkipTime, nil)
    42  	skipStep := NewSkipForTrialPlanStep(mockStep)
    43  
    44  	// When
    45  	gotOperation, gotSkipTime, gotErr := skipStep.Run(givenOperation1, log)
    46  
    47  	// Then
    48  	mockStep.AssertExpectations(t)
    49  	assert.Nil(t, gotErr)
    50  	assert.Equal(t, wantSkipTime, gotSkipTime)
    51  	assert.Equal(t, wantOperation2, gotOperation)
    52  }