Skip to content

Commit

Permalink
chore(e2e): complete config integration test
Browse files Browse the repository at this point in the history
* Added configmap and secret integration tests
* Refactored to be included and run under /common dir

Ref apache#2003
  • Loading branch information
squakez committed May 17, 2021
1 parent 0f06b4c commit 841dc34
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 62 deletions.
56 changes: 53 additions & 3 deletions e2e/config/resources_test.go → e2e/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,73 @@ limitations under the License.
package resources

import (
"io/ioutil"
"testing"

. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

v1 "k8s.io/api/core/v1"

"io/ioutil"

. "github.com/apache/camel-k/e2e/support"
camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
"github.com/apache/camel-k/pkg/util/gzip"
)

func TestRunResourceExamples(t *testing.T) {
func TestRunConfigExamples(t *testing.T) {
WithNewTestNamespace(t, func(ns string) {
Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())

// Properties

t.Run("Simple property", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/property-route.groovy", "-p", "my.message=test-property").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "property-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "property-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-route"), TestTimeoutShort).Should(ContainSubstring("test-property"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

t.Run("Property file", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/property-file-route.groovy", "--property-file", "./files/my.properties").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "property-file-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "property-file-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "property-file-route"), TestTimeoutShort).Should(ContainSubstring("hello world"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

// Configmap

t.Run("Textplain configmap", func(t *testing.T) {
// Store a configmap on the cluster
var cmData = make(map[string]string)
cmData["my-configmap-key"] = "my-configmap-content"
NewPlainTextConfigmap(ns, "my-cm", cmData)

Expect(Kamel("run", "-n", ns, "./files/configmap-route.groovy", "--configmap", "my-cm").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

// Secret

t.Run("Textplain secret", func(t *testing.T) {
// Store a secret on the cluster
var secData = make(map[string]string)
secData["my-secret-key"] = "very top secret"
NewPlainTextSecret(ns, "my-sec", secData)

Expect(Kamel("run", "-n", ns, "./files/secret-route.groovy", "--secret", "my-sec").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

// Resources

t.Run("Plain text resource file", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/resources-route.groovy", "--resource", "./files/resources-data.txt").Execute()).To(Succeed())
Eventually(IntegrationPodPhase(ns, "resources-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Expand Down Expand Up @@ -69,5 +118,6 @@ func TestRunResourceExamples(t *testing.T) {
Eventually(IntegrationLogs(ns, "resources-base64-encoded-route"), TestTimeoutShort).Should(ContainSubstring(string(expectedBytes)))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

})
}
30 changes: 30 additions & 0 deletions e2e/common/config/files/configmap-route.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// camel-k: language=groovy
/*
* 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.
*/

//
// To run this integrations use:
//
// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
// kamel run --configmap my-cm configmap-route.groovy --dev
//

from('timer:configmap')
.routeId('configmap')
.setBody()
.simple("resource:classpath:my-configmap-key")
.log('configmap content is: ${body}')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions e2e/common/config/files/secret-route.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// camel-k: language=groovy
/*
* 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.
*/

//
// To run this integrations use:
//
// kubectl create secret generic my-sec --from-literal=my-secret-key="very top secret"
// kamel run --secret my-sec secret-route.groovy --dev
//

from('timer:secret')
.routeId('secret')
.setBody()
.simple("resource:classpath:my-secret-key")
.log('secret content is: ${body}')
55 changes: 0 additions & 55 deletions e2e/config/properties_test.go

This file was deleted.

5 changes: 1 addition & 4 deletions script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ test-integration: build
go test -timeout 60m -v ./e2e/common -tags=integration && \
go test -timeout 60m -v ./e2e/common/build -tags=integration && \
go test -timeout 60m -v ./e2e/common/cli -tags=integration && \
go test -timeout 60m -v ./e2e/common/config -tags=integration && \
go test -timeout 60m -v ./e2e/common/languages -tags=integration && \
go test -timeout 60m -v ./e2e/common/traits -tags=integration

Expand All @@ -167,10 +168,6 @@ test-local: build
STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/local -tags=integration
#go test -timeout 60m -v ./e2e/local -tags=integration

test-resources: build
STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/config -tags=integration
#go test -timeout 60m -v ./e2e/config -tags=integration

test-kamel-cli: build
STAGING_RUNTIME_REPO="$(STAGING_RUNTIME_REPO)" go test -timeout 60m -v ./e2e/common/cli -tags=integration
#go test -timeout 60m -v ./e2e/common/cli -tags=integration
Expand Down

0 comments on commit 841dc34

Please sign in to comment.