github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/tests/remote-secret/target-current-namespace.go (about)

     1  package remotesecret
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/devfile/library/v2/pkg/util"
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  	"github.com/redhat-appstudio/e2e-tests/pkg/framework"
    11  	"github.com/redhat-appstudio/e2e-tests/pkg/utils"
    12  	"github.com/redhat-appstudio/remote-secret/api/v1beta1"
    13  	v1 "k8s.io/api/core/v1"
    14  	"k8s.io/apimachinery/pkg/api/meta"
    15  )
    16  
    17  /*
    18   * Component: remote secret
    19   * Description: SVPI-558 - Test all the options of the authz of remote secret target deployment
    20   * Test case: Target to the same namespace where the remote secret lives is always deployed
    21   */
    22  
    23  var _ = framework.RemoteSecretSuiteDescribe(Label("remote-secret", "target-current-namespace"), func() {
    24  
    25  	defer GinkgoRecover()
    26  
    27  	var fw *framework.Framework
    28  	var err error
    29  	var namespace string
    30  	var remoteSecret *v1beta1.RemoteSecret
    31  	remoteSecretName := fmt.Sprintf("test-remote-secret-%s", util.GenerateRandomString(4))
    32  	targetSecretName := ""
    33  
    34  	Describe("SVPI-558 - Target to the same namespace where the remote secret lives is always deployed", Ordered, func() {
    35  		BeforeAll(func() {
    36  			// Initialize the tests controllers
    37  			fw, err = framework.NewFramework(utils.GetGeneratedNamespace("rs-demos"))
    38  			Expect(err).NotTo(HaveOccurred())
    39  			namespace = fw.UserNamespace
    40  			Expect(namespace).NotTo(BeEmpty())
    41  		})
    42  
    43  		AfterAll(func() {
    44  			if !CurrentSpecReport().Failed() {
    45  				Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue())
    46  			}
    47  		})
    48  
    49  		It("creates RemoteSecret with a target that shares the same namespace", func() {
    50  			targets := []v1beta1.RemoteSecretTarget{{Namespace: namespace}}
    51  			remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.CreateRemoteSecret(remoteSecretName, namespace, targets, v1.SecretTypeOpaque, map[string]string{})
    52  			Expect(err).NotTo(HaveOccurred())
    53  
    54  			Eventually(func() bool {
    55  				remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecretName, namespace)
    56  				Expect(err).NotTo(HaveOccurred())
    57  
    58  				return meta.IsStatusConditionFalse(remoteSecret.Status.Conditions, "DataObtained")
    59  			}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("RemoteSecret %s/%s is not waiting for data", namespace, remoteSecretName))
    60  		})
    61  
    62  		It("creates upload secret", func() {
    63  			data := map[string]string{"a": "b", "c": "d"}
    64  
    65  			_, err = fw.AsKubeAdmin.RemoteSecretController.CreateUploadSecret(remoteSecret.Name, namespace, remoteSecret.Name, v1.SecretTypeOpaque, data)
    66  			Expect(err).NotTo(HaveOccurred())
    67  		})
    68  
    69  		It("checks if remote secret was deployed", func() {
    70  			Eventually(func() bool {
    71  				remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecretName, namespace)
    72  				Expect(err).NotTo(HaveOccurred())
    73  
    74  				return meta.IsStatusConditionTrue(remoteSecret.Status.Conditions, "Deployed")
    75  			}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("RemoteSecret %s/%s is not in deployed phase", namespace, remoteSecretName))
    76  		})
    77  
    78  		It("checks targets in RemoteSecret status", func() {
    79  			remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecret.Name, namespace)
    80  			Expect(err).NotTo(HaveOccurred())
    81  
    82  			targets := remoteSecret.Status.Targets
    83  			Expect(targets).To(HaveLen(1))
    84  
    85  			// get targetSecretName
    86  			targetSecretName = fw.AsKubeDeveloper.RemoteSecretController.GetTargetSecretName(targets, namespace)
    87  			Expect(targetSecretName).ToNot(BeEmpty())
    88  		})
    89  
    90  		It("checks if secret was created in target namespace", func() {
    91  			_, err = fw.AsKubeAdmin.CommonController.GetSecret(namespace, targetSecretName)
    92  			Expect(err).NotTo(HaveOccurred())
    93  		})
    94  	})
    95  })