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

     1  package deprovisioning
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	reconcilerApi "github.com/kyma-incubator/reconciler/pkg/keb"
     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/reconciler"
    11  	"github.com/kyma-project/kyma-environment-broker/internal/storage"
    12  	"github.com/stretchr/testify/assert"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestCheckClusterDeregistrationStep(t *testing.T) {
    17  	for tn, tc := range map[string]struct {
    18  		State                reconcilerApi.Status
    19  		ExpectedZeroDuration bool
    20  	}{
    21  		"Deleting (pending)": {
    22  			State:                reconcilerApi.StatusDeletePending,
    23  			ExpectedZeroDuration: false,
    24  		},
    25  		"Deleting": {
    26  			State:                reconcilerApi.StatusDeleting,
    27  			ExpectedZeroDuration: false,
    28  		},
    29  		"Deleted": {
    30  			State:                reconcilerApi.StatusDeleted,
    31  			ExpectedZeroDuration: true,
    32  		},
    33  		"Delete error": {
    34  			State:                reconcilerApi.StatusDeleteError,
    35  			ExpectedZeroDuration: true,
    36  		},
    37  	} {
    38  		t.Run(tn, func(t *testing.T) {
    39  			st := storage.NewMemoryStorage()
    40  			operation := fixture.FixDeprovisioningOperation("op-id", "inst-id")
    41  			operation.ClusterConfigurationVersion = 1
    42  			operation.ClusterConfigurationDeleted = true
    43  			recClient := reconciler.NewFakeClient()
    44  			recClient.ApplyClusterConfig(reconcilerApi.Cluster{
    45  				RuntimeID:    operation.RuntimeID,
    46  				RuntimeInput: reconcilerApi.RuntimeInput{},
    47  				KymaConfig:   reconcilerApi.KymaConfig{},
    48  				Metadata:     reconcilerApi.Metadata{},
    49  				Kubeconfig:   "kubeconfig",
    50  			})
    51  			recClient.ChangeClusterState(operation.RuntimeID, 1, tc.State)
    52  
    53  			step := NewCheckClusterDeregistrationStep(st.Operations(), recClient, time.Minute)
    54  			st.Operations().InsertDeprovisioningOperation(operation)
    55  
    56  			// when
    57  			_, d, err := step.Run(operation.Operation, logger.NewLogSpy().Logger)
    58  
    59  			// then
    60  			require.NoError(t, err)
    61  			if tc.ExpectedZeroDuration {
    62  				assert.Zero(t, d)
    63  			} else {
    64  				assert.NotZero(t, d)
    65  			}
    66  
    67  		})
    68  	}
    69  
    70  }