You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/11/22 10:48:56 UTC
[camel-k] 03/04: traits: add test for builder trait
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 6f9b34c8a4a4068827047316052a9592eaeeaa60
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Nov 20 23:41:06 2018 +0100
traits: add test for builder trait
---
pkg/trait/builder_test.go | 140 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 140 insertions(+)
diff --git a/pkg/trait/builder_test.go b/pkg/trait/builder_test.go
new file mode 100644
index 0000000..ef35e96
--- /dev/null
+++ b/pkg/trait/builder_test.go
@@ -0,0 +1,140 @@
+/*
+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 trait
+
+import (
+ "testing"
+
+ "github.com/apache/camel-k/pkg/builder"
+
+ "github.com/apache/camel-k/pkg/util/kubernetes"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestBuilderTraitNotAppliedBecauseOfNilContext(t *testing.T) {
+ environments := []*Environment{
+ createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterOpenShift, v1alpha1.IntegrationPlatformBuildPublishStrategyS2I),
+ createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterKubernetes, v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko),
+ }
+
+ for _, e := range environments {
+ e.Context = nil
+
+ t.Run(string(e.Platform.Spec.Cluster), func(t *testing.T) {
+ err := NewCatalog().apply(e)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, e.ExecutedTraits)
+ assert.NotContains(t, e.ExecutedTraits, ID("builder"))
+ assert.Empty(t, e.Steps)
+ })
+ }
+}
+
+func TestBuilderTraitNotAppliedBecauseOfNilPhase(t *testing.T) {
+ environments := []*Environment{
+ createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterOpenShift, v1alpha1.IntegrationPlatformBuildPublishStrategyS2I),
+ createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterKubernetes, v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko),
+ }
+
+ for _, e := range environments {
+ e.Context.Status.Phase = ""
+
+ t.Run(string(e.Platform.Spec.Cluster), func(t *testing.T) {
+ err := NewCatalog().apply(e)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, e.ExecutedTraits)
+ assert.NotContains(t, e.ExecutedTraits, ID("builder"))
+ assert.Empty(t, e.Steps)
+ })
+ }
+}
+
+func TestS2IBuilderTrait(t *testing.T) {
+ env := createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterOpenShift, v1alpha1.IntegrationPlatformBuildPublishStrategyS2I)
+ err := NewCatalog().apply(env)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, env.ExecutedTraits)
+ assert.Contains(t, env.ExecutedTraits, ID("builder"))
+ assert.NotEmpty(t, env.Steps)
+ assert.Len(t, env.Steps, 4)
+ assert.Condition(t, func() bool {
+ for _, s := range env.Steps {
+ if s.ID() == "publisher/s2i" && s.Phase() == builder.ApplicationPublishPhase {
+ return true
+ }
+ }
+
+ return false
+ })
+}
+
+func TestKanikoBuilderTrait(t *testing.T) {
+ env := createBuilderTestEnv(v1alpha1.IntegrationPlatformClusterKubernetes, v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko)
+ err := NewCatalog().apply(env)
+
+ assert.Nil(t, err)
+ assert.NotEmpty(t, env.ExecutedTraits)
+ assert.Contains(t, env.ExecutedTraits, ID("builder"))
+ assert.NotEmpty(t, env.Steps)
+ assert.Len(t, env.Steps, 4)
+ assert.Condition(t, func() bool {
+ for _, s := range env.Steps {
+ if s.ID() == "publisher/kaniko" && s.Phase() == builder.ApplicationPublishPhase {
+ return true
+ }
+ }
+
+ return false
+ })
+}
+
+func createBuilderTestEnv(cluster v1alpha1.IntegrationPlatformCluster, strategy v1alpha1.IntegrationPlatformBuildPublishStrategy) *Environment {
+ return &Environment{
+ Integration: &v1alpha1.Integration{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: "test",
+ Namespace: "ns",
+ },
+ Status: v1alpha1.IntegrationStatus{
+ Phase: v1alpha1.IntegrationPhaseDeploying,
+ },
+ },
+ Context: &v1alpha1.IntegrationContext{
+ Status: v1alpha1.IntegrationContextStatus{
+ Phase: v1alpha1.IntegrationContextPhaseBuilding,
+ },
+ },
+ Platform: &v1alpha1.IntegrationPlatform{
+ Spec: v1alpha1.IntegrationPlatformSpec{
+ Cluster: cluster,
+ Build: v1alpha1.IntegrationPlatformBuildSpec{
+ PublishStrategy: strategy,
+ Registry: "registry",
+ },
+ },
+ },
+ ExecutedTraits: make([]ID, 0),
+ Resources: kubernetes.NewCollection(),
+ }
+}