You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/06/16 12:05:04 UTC
[camel-k] 04/20: refactor(e2e): resource option integration test
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 44ba5644a1a7ad73ab196505413f520df76ea3de
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Jun 1 10:43:36 2021 +0200
refactor(e2e): resource option integration test
Ref #2003
---
e2e/common/config/config_test.go | 84 +++++++++++++---------
.../config/files/build-property-file-route.groovy | 8 ---
.../config/files/build-property-route.groovy | 8 ---
...-route.groovy => config-configmap-route.groovy} | 7 --
e2e/common/config/files/config-file-route.groovy | 5 --
...ret-route.groovy => config-secret-route.groovy} | 7 --
e2e/common/config/files/property-file-route.groovy | 6 --
e2e/common/config/files/property-route.groovy | 6 --
...oute.groovy => resource-configmap-route.groovy} | 7 +-
...y => resource-file-base64-encoded-route.groovy} | 5 --
...te.groovy => resource-file-binary-route.groovy} | 7 +-
...ces-route.groovy => resource-file-route.groovy} | 7 +-
...s-route.groovy => resource-secret-route.groovy} | 7 +-
.../user-config/resource-file-binary-route.groovy | 2 +-
pkg/trait/jvm.go | 2 +
pkg/trait/jvm_test.go | 9 +--
16 files changed, 63 insertions(+), 114 deletions(-)
diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go
index 2cb79ab..e2d16d4 100644
--- a/e2e/common/config/config_test.go
+++ b/e2e/common/config/config_test.go
@@ -59,35 +59,53 @@ func TestRunConfigExamples(t *testing.T) {
// 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", "--config", "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"]))
+ // Store a configmap on the cluster
+ var cmData = make(map[string]string)
+ cmData["my-configmap-key"] = "my-configmap-content"
+ NewPlainTextConfigmap(ns, "my-cm", cmData)
+
+ t.Run("Config configmap", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/config-configmap-route.groovy", "--config", "configmap:my-cm").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "config-configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-configmap-route"), TestTimeoutShort).Should(ContainSubstring(cmData["my-configmap-key"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
+
+ t.Run("Resource configmap", func(t *testing.T) {
+ // We can reuse the configmap created previously
+
+ Expect(Kamel("run", "-n", ns, "./files/resource-configmap-route.groovy", "--resource", "configmap:my-cm").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-configmap-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-configmap-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-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)
+ // Store a secret on the cluster
+ var secData = make(map[string]string)
+ secData["my-secret-key"] = "very top secret"
+ NewPlainTextSecret(ns, "my-sec", secData)
+
+ t.Run("Config secret", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/config-secret-route.groovy", "--config", "secret:my-sec").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "config-secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "config-secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "config-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
+ Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+ })
- Expect(Kamel("run", "-n", ns, "./files/secret-route.groovy", "--config", "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"]))
+ t.Run("Resource secret", func(t *testing.T) {
+ Expect(Kamel("run", "-n", ns, "./files/resource-secret-route.groovy", "--resource", "secret:my-sec").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-secret-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-secret-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-secret-route"), TestTimeoutShort).Should(ContainSubstring(secData["my-secret-key"]))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
- // File Configuration
+ // Config File
t.Run("Plain text configuration file", func(t *testing.T) {
Expect(Kamel("run", "-n", ns, "./files/config-file-route.groovy", "--config", "file:./files/resources-data.txt").Execute()).To(Succeed())
@@ -97,21 +115,21 @@ func TestRunConfigExamples(t *testing.T) {
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
- // Resources
+ // Resource File
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))
- Eventually(IntegrationCondition(ns, "resources-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-route.groovy", "--resource", "file:./files/resources-data.txt").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
t.Run("Binary (zip) resource file", func(t *testing.T) {
- Expect(Kamel("run", "-n", ns, "./files/resources-binary-route.groovy", "--resource", "./files/resources-data.zip", "-d", "camel-zipfile").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "resources-binary-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "resources-binary-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-binary-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-binary-route.groovy", "--resource", "file:./files/resources-data.zip", "-d", "camel-zipfile").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-binary-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-binary-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-binary-route"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
@@ -122,10 +140,10 @@ func TestRunConfigExamples(t *testing.T) {
expectedBytes, err := gzip.CompressBase64([]byte(source))
assert.Nil(t, err)
- Expect(Kamel("run", "-n", ns, "./files/resources-base64-encoded-route.groovy", "--resource", "./files/resources-data.txt", "--compression=true").Execute()).To(Succeed())
- Eventually(IntegrationPodPhase(ns, "resources-base64-encoded-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
- Eventually(IntegrationCondition(ns, "resources-base64-encoded-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
- Eventually(IntegrationLogs(ns, "resources-base64-encoded-route"), TestTimeoutShort).Should(ContainSubstring(string(expectedBytes)))
+ Expect(Kamel("run", "-n", ns, "./files/resource-file-base64-encoded-route.groovy", "--resource", "file:./files/resources-data.txt", "--compression=true").Execute()).To(Succeed())
+ Eventually(IntegrationPodPhase(ns, "resource-file-base64-encoded-route"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
+ Eventually(IntegrationCondition(ns, "resource-file-base64-encoded-route", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
+ Eventually(IntegrationLogs(ns, "resource-file-base64-encoded-route"), TestTimeoutShort).Should(ContainSubstring(string(expectedBytes)))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
diff --git a/e2e/common/config/files/build-property-file-route.groovy b/e2e/common/config/files/build-property-file-route.groovy
index 8427b48..ecb065f 100644
--- a/e2e/common/config/files/build-property-file-route.groovy
+++ b/e2e/common/config/files/build-property-file-route.groovy
@@ -16,14 +16,6 @@
* limitations under the License.
*/
-//
-// Provide a build time configuration property file
-//
-// To run this integrations use:
-//
-// kamel run --build-property=file:quarkus.properties build-property-file-route.groovy --dev
-//
-
from('timer:build-property')
.routeId('build-property')
.log('The application name: {{quarkus.application.name}}')
diff --git a/e2e/common/config/files/build-property-route.groovy b/e2e/common/config/files/build-property-route.groovy
index c32e5e6..ecb065f 100644
--- a/e2e/common/config/files/build-property-route.groovy
+++ b/e2e/common/config/files/build-property-route.groovy
@@ -16,14 +16,6 @@
* limitations under the License.
*/
-//
-// Provide a build time configuration property (the application name)
-//
-// To run this integrations use:
-//
-// kamel run --build-property=quarkus.application.name=my-super-application build-property-route.groovy --dev
-//
-
from('timer:build-property')
.routeId('build-property')
.log('The application name: {{quarkus.application.name}}')
diff --git a/e2e/common/config/files/configmap-route.groovy b/e2e/common/config/files/config-configmap-route.groovy
similarity index 83%
rename from e2e/common/config/files/configmap-route.groovy
rename to e2e/common/config/files/config-configmap-route.groovy
index 948cb15..8c82912 100644
--- a/e2e/common/config/files/configmap-route.groovy
+++ b/e2e/common/config/files/config-configmap-route.groovy
@@ -16,13 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kubectl create configmap my-cm --from-literal=my-configmap-key="configmap content"
-// kamel run --config configmap:my-cm configmap-route.groovy --dev
-//
-
from('timer:configmap')
.routeId('configmap')
.setBody()
diff --git a/e2e/common/config/files/config-file-route.groovy b/e2e/common/config/files/config-file-route.groovy
index 53b347f..37b9473 100644
--- a/e2e/common/config/files/config-file-route.groovy
+++ b/e2e/common/config/files/config-file-route.groovy
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --config file:resources-data.txt resources-route.groovy --dev
-//
-
from('timer:resources')
.routeId('resources')
.setBody()
diff --git a/e2e/common/config/files/secret-route.groovy b/e2e/common/config/files/config-secret-route.groovy
similarity index 83%
rename from e2e/common/config/files/secret-route.groovy
rename to e2e/common/config/files/config-secret-route.groovy
index 7027b84..ac369aa 100644
--- a/e2e/common/config/files/secret-route.groovy
+++ b/e2e/common/config/files/config-secret-route.groovy
@@ -16,13 +16,6 @@
* 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 --config secret:my-sec secret-route.groovy --dev
-//
-
from('timer:secret')
.routeId('secret')
.setBody()
diff --git a/e2e/common/config/files/property-file-route.groovy b/e2e/common/config/files/property-file-route.groovy
index 6ce6838..e9718df 100644
--- a/e2e/common/config/files/property-file-route.groovy
+++ b/e2e/common/config/files/property-file-route.groovy
@@ -16,12 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kamel run --property file:my.properties property-file-route.groovy --dev
-//
-
from('timer:property-file')
.routeId('property-file')
.log('property file content is: {{my.key.1}} {{my.key.2}}')
diff --git a/e2e/common/config/files/property-route.groovy b/e2e/common/config/files/property-route.groovy
index 705eca6..a609ea7 100644
--- a/e2e/common/config/files/property-route.groovy
+++ b/e2e/common/config/files/property-route.groovy
@@ -16,12 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-//
-// kamel run -p my.message=test-property property-route.groovy --dev
-//
-
from('timer:property')
.routeId('property')
.log('property content is: {{my.message}}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-configmap-route.groovy
similarity index 81%
copy from e2e/common/config/files/resources-route.groovy
copy to e2e/common/config/files/resource-configmap-route.groovy
index 1085840..3df9e05 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-configmap-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/configmaps/my-cm/?fileName=my-configmap-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resources-base64-encoded-route.groovy b/e2e/common/config/files/resource-file-base64-encoded-route.groovy
similarity index 87%
rename from e2e/common/config/files/resources-base64-encoded-route.groovy
rename to e2e/common/config/files/resource-file-base64-encoded-route.groovy
index 02559f0..8cbff0b 100644
--- a/e2e/common/config/files/resources-base64-encoded-route.groovy
+++ b/e2e/common/config/files/resource-file-base64-encoded-route.groovy
@@ -16,11 +16,6 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt --compression=true resources-base64-encoded-route.groovy --dev
-//
-
from('timer:resources-bas64')
.routeId('resources-base64')
.setBody()
diff --git a/e2e/common/config/files/resources-binary-route.groovy b/e2e/common/config/files/resource-file-binary-route.groovy
similarity index 80%
rename from e2e/common/config/files/resources-binary-route.groovy
rename to e2e/common/config/files/resource-file-binary-route.groovy
index 8b0878b..c6faa9a 100644
--- a/e2e/common/config/files/resources-binary-route.groovy
+++ b/e2e/common/config/files/resource-file-binary-route.groovy
@@ -16,12 +16,7 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.zip resources-binary-route.groovy -d camel-zipfile --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-file-route.groovy
similarity index 81%
copy from e2e/common/config/files/resources-route.groovy
copy to e2e/common/config/files/resource-file-route.groovy
index 1085840..6ab0338 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-file-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/e2e/common/config/files/resources-route.groovy b/e2e/common/config/files/resource-secret-route.groovy
similarity index 81%
rename from e2e/common/config/files/resources-route.groovy
rename to e2e/common/config/files/resource-secret-route.groovy
index 1085840..c2e5685 100644
--- a/e2e/common/config/files/resources-route.groovy
+++ b/e2e/common/config/files/resource-secret-route.groovy
@@ -16,10 +16,5 @@
* limitations under the License.
*/
-//
-// To run this integrations use:
-// kamel run --resource resources-data.txt resources-route.groovy --dev
-//
-
-from('file:/etc/camel/resources/?fileName=resources-data.txt&noop=true&idempotent=false')
+from('file:/etc/camel/data/secrets/my-sec/?fileName=my-secret-key&noop=true&idempotent=false')
.log('resource file content is: ${body}')
diff --git a/examples/user-config/resource-file-binary-route.groovy b/examples/user-config/resource-file-binary-route.groovy
index eef04d1..2121c26 100644
--- a/examples/user-config/resource-file-binary-route.groovy
+++ b/examples/user-config/resource-file-binary-route.groovy
@@ -21,7 +21,7 @@
// kamel run --resource resources-data.zip resource-file-binary-route.groovy -d camel-zipfile --dev
//
-from('file:/etc/camel/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
+from('file:/etc/camel/data/resources/?fileName=resources-data.zip&noop=true&idempotent=false')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 725f84c..c30a3aa 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -96,6 +96,8 @@ func (t *jvmTrait) Apply(e *Environment) error {
classpath := strset.New()
classpath.Add("./resources")
+ classpath.Add(configResourcesMountPath)
+ classpath.Add(dataResourcesMountPath)
for _, artifact := range kit.Status.Artifacts {
classpath.Add(artifact.Target)
diff --git a/pkg/trait/jvm_test.go b/pkg/trait/jvm_test.go
index cfa925c..f5bc7d1 100644
--- a/pkg/trait/jvm_test.go
+++ b/pkg/trait/jvm_test.go
@@ -19,6 +19,7 @@ package trait
import (
"context"
+ "fmt"
"sort"
"strings"
"testing"
@@ -103,12 +104,12 @@ func TestApplyJvmTraitWithDeploymentResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/mount/path",
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, d.Spec.Template.Spec.Containers[0].Args)
}
@@ -135,12 +136,12 @@ func TestApplyJvmTraitWithKNativeResource(t *testing.T) {
assert.Nil(t, err)
- cp := strset.New("./resources", "/mount/path").List()
+ cp := strset.New("./resources", configResourcesMountPath, dataResourcesMountPath, "/mount/path").List()
sort.Strings(cp)
assert.Equal(t, []string{
"-cp",
- "./resources:/mount/path",
+ fmt.Sprintf("./resources:%s:%s:/mount/path", configResourcesMountPath, dataResourcesMountPath),
"io.quarkus.bootstrap.runner.QuarkusEntryPoint",
}, s.Spec.Template.Spec.Containers[0].Args)
}