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

chore(e2e): config test #2295

Merged
merged 5 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
build/_output
build/_test
build/_maven_output
build/_maven_overlay
build/_kamelets
/api_*

Expand Down
123 changes: 123 additions & 0 deletions e2e/common/config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// +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 resources

import (
"io/ioutil"
"testing"

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

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

. "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 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))
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("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("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

t.Run("Base64 compressed binary resource file", func(t *testing.T) {
// We calculate the expected content
source, err := ioutil.ReadFile("./files/resources-data.txt")
assert.Nil(t, err)
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("delete", "--all", "-n", ns).Execute()).To(Succeed())
})

})
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// camel-k: language=groovy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -14,27 +15,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class ResourcesBinary extends org.apache.camel.builder.RouteBuilder {
//
// 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
//

@Override
public void configure() throws Exception {
from("file:/etc/camel/resources/i-resource-000/?noop=true")
.unmarshal().zipFile()
.convertBodyTo(String.class)
.process(new ZipEntryProcessor());
}

}

class ZipEntryProcessor implements Processor {

@Override
public void process(Exchange exchange) throws Exception {
System.out.println(exchange.getIn().getBody().toString());
}

}
from('timer:configmap')
.routeId('configmap')
.setBody()
.simple("resource:classpath:my-configmap-key")
.log('configmap content is: ${body}')
2 changes: 2 additions & 0 deletions e2e/common/config/files/my.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
my.key.1=hello
my.key.2=world
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// camel-k: language=groovy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
Expand All @@ -14,16 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class ResourcesText extends org.apache.camel.builder.RouteBuilder {
//
// To run this integrations use:
//
// kamel run --property-file my.properties property-file-route.groovy --dev
//

@Override
public void configure() throws Exception {
from("file:/etc/camel/resources/i-resource-000/?noop=true")
.log("${body}");
}

}
from('timer:property-file')
.routeId('property-file')
.log('property file content is: {{my.key.1}} {{my.key.2}}')
27 changes: 27 additions & 0 deletions e2e/common/config/files/property-route.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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:
//
// kamel run -p my.message=test-property property-route.groovy --dev
//

from('timer:property')
.routeId('property')
.log('property content is: {{my.message}}')
28 changes: 28 additions & 0 deletions e2e/common/config/files/resources-base64-encoded-route.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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:
// kamel run --resource resources-data.txt --compression=true resources-base64-encoded-route.groovy --dev
//

from('timer:resources-bas64')
.routeId('resources-base64')
.setBody()
.simple("resource:classpath:resources-data.txt")
.log('resource file base64 content is: ${body}')
27 changes: 27 additions & 0 deletions e2e/common/config/files/resources-binary-route.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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:
// 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')
.routeId('resources-zip')
.unmarshal().zipFile()
.log('resource file unzipped content is: ${body}')
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@

//
// To run this integrations use:
//
// kamel run --resource examples/resources-data.txt examples/resources-route.groovy
// kamel run --resource resources-data.txt resources-route.groovy --dev
//

from('timer:resources')
.routeId('resources')
.setBody()
.simple("resource:classpath:resources-data.txt")
.log('file content is: ${body}')
.log('resource file content is: ${body}')
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}')
56 changes: 0 additions & 56 deletions e2e/resources/resources_test.go

This file was deleted.

Loading