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

     1  package deprovisioning
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-project/kyma-environment-broker/internal"
     7  
     8  	"github.com/kyma-project/kyma-environment-broker/internal/fixture"
     9  	"github.com/kyma-project/kyma-environment-broker/internal/logger"
    10  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    11  	"github.com/stretchr/testify/assert"
    12  	"sigs.k8s.io/controller-runtime/pkg/client/fake"
    13  )
    14  
    15  const kymaTemplate = `
    16  apiVersion: operator.kyma-project.io/v1beta2
    17  kind: Kyma
    18  metadata:
    19    name: my-kyma
    20    namespace: kyma-system
    21  spec:
    22    sync:
    23      strategy: secret
    24    channel: stable
    25    modules: []
    26  `
    27  
    28  func TestDeleteKymaResource_HappyFlow(t *testing.T) {
    29  	// Given
    30  	operation := fixture.FixDeprovisioningOperationAsOperation(fixOperationID, fixInstanceID)
    31  	operation.KymaResourceNamespace = "kyma-system"
    32  
    33  	kcpClient := fake.NewClientBuilder().Build()
    34  	memoryStorage := storage.NewMemoryStorage()
    35  	err := memoryStorage.Operations().InsertOperation(operation)
    36  	assert.NoError(t, err)
    37  
    38  	step := NewDeleteKymaResourceStep(memoryStorage.Operations(), kcpClient, fakeConfigProvider{}, "2.0")
    39  	memoryStorage.Operations().InsertOperation(operation)
    40  
    41  	// When
    42  	_, backoff, err := step.Run(operation, logger.NewLogSpy().Logger)
    43  
    44  	// Then
    45  	assert.Zero(t, backoff)
    46  }
    47  
    48  func TestDeleteKymaResource_EmptyRuntimeIDAndKymaResourceName(t *testing.T) {
    49  	// Given
    50  	operation := fixture.FixDeprovisioningOperationAsOperation(fixOperationID, fixInstanceID)
    51  	operation.KymaResourceNamespace = "kyma-system"
    52  	operation.RuntimeID = ""
    53  	operation.KymaResourceName = ""
    54  
    55  	kcpClient := fake.NewClientBuilder().Build()
    56  	memoryStorage := storage.NewMemoryStorage()
    57  	err := memoryStorage.Operations().InsertOperation(operation)
    58  	assert.NoError(t, err)
    59  
    60  	step := NewDeleteKymaResourceStep(memoryStorage.Operations(), kcpClient, fakeConfigProvider{}, "2.0")
    61  	memoryStorage.Operations().InsertOperation(operation)
    62  
    63  	// When
    64  	_, backoff, err := step.Run(operation, logger.NewLogSpy().Logger)
    65  
    66  	// Then
    67  	assert.Zero(t, backoff)
    68  }
    69  
    70  type fakeConfigProvider struct {
    71  }
    72  
    73  func (fakeConfigProvider) ProvideForGivenVersionAndPlan(_, _ string) (*internal.ConfigForPlan, error) {
    74  	return &internal.ConfigForPlan{
    75  		KymaTemplate: kymaTemplate,
    76  	}, nil
    77  }