From 629f0d84f712d688e608d893e6797d60535efd74 Mon Sep 17 00:00:00 2001 From: realMartinez Date: Mon, 5 Feb 2024 12:04:45 +0100 Subject: [PATCH] chore: added E2E test for logging category --- e2e/common/traits/logging_test.go | 72 +++++++++++++++++++++++++++++++ pkg/trait/logging_test.go | 8 ++-- 2 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 e2e/common/traits/logging_test.go diff --git a/e2e/common/traits/logging_test.go b/e2e/common/traits/logging_test.go new file mode 100644 index 0000000000..a018807417 --- /dev/null +++ b/e2e/common/traits/logging_test.go @@ -0,0 +1,72 @@ +//go:build integration +// +build integration + +// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration" + +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package traits + +import ( + "testing" + + . "github.com/apache/camel-k/v2/e2e/support" + . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" +) + +func TestLoggingCategory(t *testing.T) { + RegisterTestingT(t) + + operatorID := "camel-k" + + t.Run("Test debug log evel", func(t *testing.T) { + name := RandomizedSuffixName("java") + Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name, "-t", "logging.category.'org.apache.camel.impl'=DEBUG").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + logTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "logging", "category") + Expect(logTrait).ToNot(BeNil()) + Expect(len(logTrait)).To(Equal(1)) + Expect(logTrait["org.apache.camel.impl"]).To(Equal("DEBUG")) + + Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil()) + }) + + t.Run("Test multiple log levels", func(t *testing.T) { + name := RandomizedSuffixName("java") + Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name, + "-t", "logging.category.'org.apache.camel.impl'=DEBUG", + "-t", "logging.category.'org.jboss.resteasy'=DEBUG").Execute()).To(Succeed()) + Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + logTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "logging", "category") + Expect(logTrait).ToNot(BeNil()) + Expect(len(logTrait)).To(Equal(2)) + Expect(logTrait["org.apache.camel.impl"]).To(Equal("DEBUG")) + Expect(logTrait["org.jboss.resteasy"]).To(Equal("DEBUG")) + + Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil()) + }) + +} diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go index 27b7597acd..9e3abc59f4 100644 --- a/pkg/trait/logging_test.go +++ b/pkg/trait/logging_test.go @@ -220,7 +220,7 @@ func TestSingleLoggingCategory(t *testing.T) { env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n", map[string]string{}) env.Integration.Spec.Traits = v1.Traits{ Logging: &traitv1.LoggingTrait{ - Category: map[string]string{"org.test": "debug"}, + Category: map[string]string{"org.apache.camel.impl": "debug"}, }, } conditions, err := NewLoggingTestCatalog().apply(env) @@ -228,7 +228,7 @@ func TestSingleLoggingCategory(t *testing.T) { assert.Nil(t, err) assert.Empty(t, conditions) - testEnvVar := corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_TEST_LEVEL", "DEBUG", nil} + testEnvVar := corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_APACHE_CAMEL_IMPL_LEVEL", "DEBUG", nil} assert.Contains(t, env.EnvVars, testEnvVar) } @@ -236,7 +236,7 @@ func TestLoggingCategories(t *testing.T) { env := createLoggingTestEnv(t, true, true, false, "TRACE", "%d{HH:mm:ss} %-5p (%t) %s%e%n", map[string]string{}) env.Integration.Spec.Traits = v1.Traits{ Logging: &traitv1.LoggingTrait{ - Category: map[string]string{"org.test": "debug", "org.jboss.resteasy": "debug"}, + Category: map[string]string{"org.apache.camel.impl": "debug", "org.jboss.resteasy": "debug"}, }, } conditions, err := NewLoggingTestCatalog().apply(env) @@ -244,7 +244,7 @@ func TestLoggingCategories(t *testing.T) { assert.Nil(t, err) testEnvVars := []corev1.EnvVar{ - corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_TEST_LEVEL", "DEBUG", nil}, + corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_APACHE_CAMEL_IMPL_LEVEL", "DEBUG", nil}, corev1.EnvVar{"QUARKUS_LOG_CATEGORY_ORG_JBOSS_RESTEASY_LEVEL", "DEBUG", nil}, }