Skip to content

Commit

Permalink
chore: added E2E test for logging category
Browse files Browse the repository at this point in the history
  • Loading branch information
realMartinez committed Feb 29, 2024
1 parent 027dacb commit 629f0d8
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
72 changes: 72 additions & 0 deletions e2e/common/traits/logging_test.go
Original file line number Diff line number Diff line change
@@ -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())
})

}
8 changes: 4 additions & 4 deletions pkg/trait/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,31 @@ 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)

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)
}

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)
assert.Empty(t, conditions)
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},
}

Expand Down

0 comments on commit 629f0d8

Please sign in to comment.