-
Notifications
You must be signed in to change notification settings - Fork 92
/
get-file-content-rs.go
125 lines (100 loc) · 4.69 KB
/
get-file-content-rs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package spi
import (
"fmt"
"os"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/redhat-appstudio/e2e-tests/pkg/constants"
"github.com/redhat-appstudio/e2e-tests/pkg/framework"
"github.com/redhat-appstudio/e2e-tests/pkg/utils"
rs "github.com/redhat-appstudio/remote-secret/api/v1beta1"
"github.com/redhat-appstudio/service-provider-integration-operator/api/v1beta1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
)
/*
* Component: spi
* Description: SVPI-402 - Get file content from a private Github repository
* Use case: Remote Secret Usage
*/
var _ = framework.SPISuiteDescribe(Label("spi-suite", "get-file-content-rs"), func() {
defer GinkgoRecover()
var fw *framework.Framework
var err error
var namespace, targetSecretName string
var remoteSecret *rs.RemoteSecret
var SPIFcr *v1beta1.SPIFileContentRequest
remoteSecretName := "test-remote-secret"
AfterEach(framework.ReportFailure(&fw))
Describe("SVPI-402 - Get file content from a private Github repository with Remote Secret", Ordered, func() {
BeforeAll(func() {
if os.Getenv("CI") != "true" {
Skip(fmt.Sprintln("test skipped on local execution"))
}
// Initialize the tests controllers
fw, err = framework.NewFramework(utils.GetGeneratedNamespace("spi-demos"))
Expect(err).NotTo(HaveOccurred())
namespace = fw.UserNamespace
Expect(namespace).NotTo(BeEmpty())
// collect SPI ResourceQuota metrics (temporary)
err := fw.AsKubeAdmin.CommonController.GetResourceQuotaInfo("get-file-content-rs", namespace, "appstudio-crds-spi")
Expect(err).NotTo(HaveOccurred())
})
AfterAll(func() {
// collect SPI ResourceQuota metrics (temporary)
err := fw.AsKubeAdmin.CommonController.GetResourceQuotaInfo("get-file-content-rs", namespace, "appstudio-crds-spi")
Expect(err).NotTo(HaveOccurred())
if !CurrentSpecReport().Failed() {
Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue())
}
})
It("creates RemoteSecret", func() {
targets := []rs.RemoteSecretTarget{{Namespace: namespace}}
labels := map[string]string{"appstudio.redhat.com/sp.host": "github.com"}
remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.CreateRemoteSecret(remoteSecretName, namespace, targets, v1.SecretTypeBasicAuth, labels)
Expect(err).NotTo(HaveOccurred())
Eventually(func() bool {
remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecretName, namespace)
Expect(err).NotTo(HaveOccurred())
return meta.IsStatusConditionFalse(remoteSecret.Status.Conditions, "DataObtained")
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("RemoteSecret %s/%s is not waiting for data", namespace, remoteSecretName))
})
It("creates upload secret", func() {
data := map[string]string{
"password": utils.GetEnv(constants.GITHUB_TOKEN_ENV, ""),
}
_, err = fw.AsKubeAdmin.RemoteSecretController.CreateUploadSecret(remoteSecret.Name, namespace, remoteSecret.Name, v1.SecretTypeBasicAuth, data)
Expect(err).NotTo(HaveOccurred())
})
It("checks if remote secret was deployed", func() {
Eventually(func() bool {
remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecretName, namespace)
Expect(err).NotTo(HaveOccurred())
return meta.IsStatusConditionTrue(remoteSecret.Status.Conditions, "Deployed")
}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("RemoteSecret %s/%s is not in deployed phase", namespace, remoteSecretName))
})
It("checks targets in RemoteSecret status", func() {
remoteSecret, err = fw.AsKubeDeveloper.RemoteSecretController.GetRemoteSecret(remoteSecret.Name, namespace)
Expect(err).NotTo(HaveOccurred())
targets := remoteSecret.Status.Targets
Expect(targets).To(HaveLen(1))
// get targetSecretName
targetSecretName = fw.AsKubeDeveloper.RemoteSecretController.GetTargetSecretName(targets, namespace)
Expect(targetSecretName).ToNot(BeEmpty())
})
It("checks if secret was created in target namespace", func() {
_, err = fw.AsKubeAdmin.CommonController.GetSecret(namespace, targetSecretName)
Expect(err).NotTo(HaveOccurred())
})
It("creates SPIFileContentRequest", func() {
SPIFcr, err = fw.AsKubeDeveloper.SPIController.CreateSPIFileContentRequest("gh-spi-filecontent-request", namespace, GithubPrivateRepoURL, GithubPrivateRepoFilePath)
Expect(err).NotTo(HaveOccurred())
SPIFcr, err = fw.AsKubeDeveloper.SPIController.GetSPIFileContentRequest(SPIFcr.Name, namespace)
Expect(err).NotTo(HaveOccurred())
})
It("SPIFileContentRequest should be in Delivered phase and content should be provided", func() {
fw.AsKubeDeveloper.SPIController.IsSPIFileContentRequestInDeliveredPhase(SPIFcr)
})
})
})