Skip to content

Commit

Permalink
feat(test): binary data integration test
Browse files Browse the repository at this point in the history
* Added integration test for apache#1946
  • Loading branch information
squakez committed Feb 3, 2021
1 parent 3d45999 commit efef9b4
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
40 changes: 40 additions & 0 deletions e2e/resources/files/ResourcesBinary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.
*/

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

public class ResourcesBinary extends org.apache.camel.builder.RouteBuilder {

@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());
}

}
29 changes: 29 additions & 0 deletions e2e/resources/files/ResourcesText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/

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

public class ResourcesText extends org.apache.camel.builder.RouteBuilder {

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

}
1 change: 1 addition & 0 deletions e2e/resources/files/resources-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
the file body
Binary file added e2e/resources/files/resources-data.zip
Binary file not shown.
57 changes: 57 additions & 0 deletions e2e/resources/resources_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// +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 (
"testing"

. "github.com/apache/camel-k/e2e/support"
camelv1 "github.com/apache/camel-k/pkg/apis/camel/v1"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
)

func TestRunResourceExamples(t *testing.T) {

WithNewTestNamespace(t, func(ns string) {
Expect(Kamel("install", "-n", ns).Execute()).Should(BeNil())

t.Run("run java", func(t *testing.T) {
RegisterTestingT(t)
Expect(Kamel("run", "-n", ns, "./files/ResourcesText.java", "--resource", "./files/resources-data.txt").Execute()).Should(BeNil())
Eventually(IntegrationPodPhase(ns, "resources-text"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "resources-text", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "resources-text"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})

t.Run("run java", func(t *testing.T) {
RegisterTestingT(t)
Expect(Kamel("run", "-n", ns, "./files/ResourcesBinary.java",
"--resource", "./files/resources-data.zip", "-d", "camel-zipfile").Execute()).Should(BeNil())
Eventually(IntegrationPodPhase(ns, "resources-binary"), TestTimeoutMedium).Should(Equal(v1.PodRunning))
Eventually(IntegrationCondition(ns, "resources-binary", camelv1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(v1.ConditionTrue))
Eventually(IntegrationLogs(ns, "resources-binary"), TestTimeoutShort).Should(ContainSubstring("the file body"))
Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})
})
}
4 changes: 4 additions & 0 deletions script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ 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/resources -tags=integration
#go test -timeout 60m -v ./e2e/resources -tags=integration

build-kamel:
go build $(GOFLAGS) -o kamel ./cmd/kamel/*.go

Expand Down

0 comments on commit efef9b4

Please sign in to comment.