github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/steps/lifecycle_manager_kubeconfig_test.go (about) 1 package steps 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 8 "github.com/kyma-project/kyma-environment-broker/internal/logger" 9 "github.com/kyma-project/kyma-environment-broker/internal/storage" 10 "github.com/stretchr/testify/assert" 11 v1 "k8s.io/api/core/v1" 12 "k8s.io/apimachinery/pkg/api/errors" 13 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 "k8s.io/apimachinery/pkg/types" 15 "sigs.k8s.io/controller-runtime/pkg/client/fake" 16 ) 17 18 func TestCheckKymaKubeconfigCreated(t *testing.T) { 19 // Given 20 operation := fixture.FixProvisioningOperation("op", "instance") 21 operation.KymaResourceNamespace = "kyma-system" 22 23 k8sClient := fake.NewClientBuilder().Build() 24 25 memoryStorage := storage.NewMemoryStorage() 26 err := memoryStorage.Operations().InsertOperation(operation) 27 assert.NoError(t, err) 28 29 step := SyncKubeconfig(memoryStorage.Operations(), k8sClient) 30 31 // When 32 _, backoff, err := step.Run(operation, logger.NewLogSpy().Logger) 33 34 // Then 35 assert.Zero(t, backoff) 36 37 sec := v1.Secret{} 38 err = k8sClient.Get(context.Background(), types.NamespacedName{Namespace: "kyma-system", Name: "kubeconfig-runtime-instance"}, &sec) 39 assert.NoError(t, err) 40 } 41 42 func TestCheckKymaKubeconfigDeleted(t *testing.T) { 43 // Given 44 operation := fixture.FixDeprovisioningOperationAsOperation("op", "instance") 45 operation.KymaResourceNamespace = "kyma-system" 46 47 k8sClient := fake.NewClientBuilder().Build() 48 err := k8sClient.Create(context.Background(), &v1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "kyma-system", Name: "kubeconfig-runtime-instance"}}) 49 assert.NoError(t, err) 50 51 memoryStorage := storage.NewMemoryStorage() 52 err = memoryStorage.Operations().InsertOperation(operation) 53 assert.NoError(t, err) 54 55 step := DeleteKubeconfig(memoryStorage.Operations(), k8sClient) 56 57 // When 58 _, backoff, err := step.Run(operation, logger.NewLogSpy().Logger) 59 60 // Then 61 assert.Zero(t, backoff) 62 63 sec := v1.Secret{} 64 err = k8sClient.Get(context.Background(), types.NamespacedName{Namespace: "kyma-system", Name: "kubeconfig-runtime-instance"}, &sec) 65 assert.Error(t, err) 66 assert.True(t, errors.IsNotFound(err)) 67 } 68 69 func TestCheckKymaKubeconfigDeleteSkipped(t *testing.T) { 70 // Given 71 operation := fixture.FixDeprovisioningOperationAsOperation("op", "instance") 72 73 k8sClient := fake.NewClientBuilder().Build() 74 75 memoryStorage := storage.NewMemoryStorage() 76 err := memoryStorage.Operations().InsertOperation(operation) 77 assert.NoError(t, err) 78 79 step := DeleteKubeconfig(memoryStorage.Operations(), k8sClient) 80 81 // When 82 _, backoff, err := step.Run(operation, logger.NewLogSpy().Logger) 83 84 // Then 85 assert.Zero(t, backoff) 86 assert.NoError(t, err) 87 }