Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2e): Ensures Maven proxy test is not infra dependant #5581

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions e2e/advanced/maven_http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ func TestMavenProxy(t *testing.T) {

// Install Camel K with the HTTP proxy
operatorID := "camel-k-maven-proxy"
g.Expect(CopyCamelCatalog(t, ctx, ns, operatorID)).To(Succeed())
g.Expect(CopyIntegrationKits(t, ctx, ns, operatorID)).To(Succeed())
olm, olmErr := olm.IsAPIAvailable(TestClient(t))
installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(t), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name())
permission, pErr := kubernetes.CheckPermission(ctx, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit")
Expand Down Expand Up @@ -210,10 +208,6 @@ func TestMavenProxy(t *testing.T) {
g.Expect(err).To(Succeed())
g.Expect(proxies.Items).To(HaveLen(1))

logs := Logs(t, ctx, ns, proxies.Items[0].Name, corev1.PodLogOptions{})()
g.Expect(logs).NotTo(BeEmpty())
g.Expect(logs).To(ContainSubstring("\"CONNECT repo.maven.apache.org:443 HTTP/1.1\" 200"))

// Clean up
g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed())
g.Expect(TestClient(t).Delete(ctx, deployment)).To(Succeed())
Expand All @@ -223,6 +217,51 @@ func TestMavenProxy(t *testing.T) {
})
}

func TestMavenProxyNotPresent(t *testing.T) {
t.Parallel()

WithNewTestNamespace(t, func(ctx context.Context, g *WithT, ns string) {
hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns)

svc := Service(t, ctx, TestDefaultNamespace, "kubernetes")()
g.Expect(svc).NotTo(BeNil())
// It may be needed to populate the values from the cluster, machine and service network CIDRs
noProxy := []string{
".cluster.local",
".svc",
"localhost",
}
noProxy = append(noProxy, svc.Spec.ClusterIPs...)

// Install Camel K with the HTTP proxy that does not exists
operatorID := "camel-k-maven-no-proxy"
olm, olmErr := olm.IsAPIAvailable(TestClient(t))
installed, inErr := kubernetes.IsAPIResourceInstalled(TestClient(t), configv1.GroupVersion.String(), reflect.TypeOf(configv1.Proxy{}).Name())
permission, pErr := kubernetes.CheckPermission(ctx, TestClient(t), configv1.GroupName, reflect.TypeOf(configv1.Proxy{}).Name(), "", "cluster", "edit")
olmInstall := pErr == nil && olmErr == nil && inErr == nil && olm && installed && permission
if olmInstall {
// ENV values should be injected by the OLM
g.Expect(KamelInstallWithID(t, ctx, operatorID, ns)).To(Succeed())
} else {
g.Expect(KamelInstallWithID(t, ctx, operatorID, ns, "--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname), "--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","))).To(Succeed())
}

g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

// Run the Integration
name := RandomizedSuffixName("java")
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed())

// Should not be able to build
g.Eventually(IntegrationPhase(t, ctx, ns, name)).Should(Equal(v1.IntegrationPhaseError))
g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionKitAvailable)).
Should(Equal(corev1.ConditionFalse))

// Clean up
g.Expect(Kamel(t, ctx, "delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}

func newHTTPDConfigMap(ns, hostname string) *corev1.ConfigMap {
return &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Expand Down