This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new 9f90e77  fix: Dependencies & rest-dsl traits are never enabled
9f90e77 is described below

commit 9f90e77eb3958e532d23e45309f243e37efee21e
Author: James Netherton <jamesnether...@gmail.com>
AuthorDate: Fri Jul 5 10:58:56 2019 +0100

    fix: Dependencies & rest-dsl traits are never enabled
    
    fixes #807
---
 pkg/trait/dependencies.go      |   2 +-
 pkg/trait/dependencies_test.go | 121 +++++++++++++++++++++++++++++++++++++++++
 pkg/trait/rest-dsl.go          |   2 +-
 pkg/trait/rest-dsl_test.go     |  57 +++++++++++++++++++
 pkg/util/kubernetes/util.go    |   2 +-
 5 files changed, 181 insertions(+), 3 deletions(-)

diff --git a/pkg/trait/dependencies.go b/pkg/trait/dependencies.go
index 5a0ad25..d12d777 100644
--- a/pkg/trait/dependencies.go
+++ b/pkg/trait/dependencies.go
@@ -40,7 +40,7 @@ func (t *dependenciesTrait) Configure(e *Environment) (bool, 
error) {
                return false, nil
        }
 
-       return e.IntegrationInPhase(""), nil
+       return e.IntegrationInPhase(v1alpha1.IntegrationPhaseInitialization), 
nil
 }
 
 func (t *dependenciesTrait) Apply(e *Environment) error {
diff --git a/pkg/trait/dependencies_test.go b/pkg/trait/dependencies_test.go
new file mode 100644
index 0000000..774c17b
--- /dev/null
+++ b/pkg/trait/dependencies_test.go
@@ -0,0 +1,121 @@
+/*
+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/apis/camel/v1alpha1"
+       "github.com/apache/camel-k/pkg/util/test"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestDependenciesTraitApplicability(t *testing.T) {
+       e := &Environment{
+               Integration: &v1alpha1.Integration{},
+       }
+
+       trait := newDependenciesTrait()
+       enabled, err := trait.Configure(e)
+       assert.Nil(t, err)
+       assert.False(t, enabled)
+
+       e.Integration.Status.Phase = v1alpha1.IntegrationPhaseNone
+       enabled, err = trait.Configure(e)
+       assert.Nil(t, err)
+       assert.False(t, enabled)
+
+       e.Integration.Status.Phase = v1alpha1.IntegrationPhaseInitialization
+       enabled, err = trait.Configure(e)
+       assert.Nil(t, err)
+       assert.True(t, enabled)
+}
+
+func TestIntegrationDefaultDeps(t *testing.T) {
+       catalog, err := test.DefaultCatalog()
+       assert.Nil(t, err)
+
+       e := &Environment{
+               CamelCatalog: catalog,
+               Integration: &v1alpha1.Integration{
+                       Spec: v1alpha1.IntegrationSpec{
+                               Sources: []v1alpha1.SourceSpec{
+                                       {
+                                               DataSpec: v1alpha1.DataSpec{
+                                                       Name:    "Request.java",
+                                                       Content: 
`from("direct:foo").to("log:bar");`,
+                                               },
+                                               Language: 
v1alpha1.LanguageJavaSource,
+                                       },
+                               },
+                       },
+                       Status: v1alpha1.IntegrationStatus{
+                               Phase: v1alpha1.IntegrationPhaseInitialization,
+                       },
+               },
+       }
+
+       trait := newDependenciesTrait()
+       enabled, err := trait.Configure(e)
+       assert.Nil(t, err)
+       assert.True(t, enabled)
+
+       err = trait.Apply(e)
+       assert.Nil(t, err)
+       assert.ElementsMatch(t, []string{"camel:core", "camel:direct", 
"camel:log", "runtime:jvm"}, e.Integration.Status.Dependencies)
+}
+
+func TestIntegrationCustomDeps(t *testing.T) {
+       catalog, err := test.DefaultCatalog()
+       assert.Nil(t, err)
+
+       e := &Environment{
+               CamelCatalog: catalog,
+               Integration: &v1alpha1.Integration{
+                       Spec: v1alpha1.IntegrationSpec{
+                               Dependencies: []string{
+                                       "camel:undertow",
+                                       "org.foo:bar",
+                               },
+                               Sources: []v1alpha1.SourceSpec{
+                                       {
+                                               DataSpec: v1alpha1.DataSpec{
+                                                       Name:    "Request.java",
+                                                       Content: 
`from("direct:foo").to("log:bar");`,
+                                               },
+                                               Language: 
v1alpha1.LanguageJavaSource,
+                                       },
+                               },
+                       },
+                       Status: v1alpha1.IntegrationStatus{
+                               Phase: v1alpha1.IntegrationPhaseInitialization,
+                       },
+               },
+       }
+
+       trait := newDependenciesTrait()
+       enabled, err := trait.Configure(e)
+       assert.Nil(t, err)
+       assert.True(t, enabled)
+
+       err = trait.Apply(e)
+       assert.Nil(t, err)
+       assert.ElementsMatch(t, []string{"camel:core", "camel:direct", 
"camel:log",
+               "camel:undertow", "org.foo:bar", "runtime:jvm"}, 
e.Integration.Status.Dependencies)
+}
diff --git a/pkg/trait/rest-dsl.go b/pkg/trait/rest-dsl.go
index ab1789d..ef6b22b 100644
--- a/pkg/trait/rest-dsl.go
+++ b/pkg/trait/rest-dsl.go
@@ -60,7 +60,7 @@ func (t *restDslTrait) Configure(e *Environment) (bool, 
error) {
 
        for _, resource := range e.Integration.Spec.Resources {
                if resource.Type == v1alpha1.ResourceTypeOpenAPI {
-                       return e.IntegrationInPhase(""), nil
+                       return 
e.IntegrationInPhase(v1alpha1.IntegrationPhaseInitialization), nil
                }
        }
 
diff --git a/pkg/trait/rest-dsl_test.go b/pkg/trait/rest-dsl_test.go
new file mode 100644
index 0000000..e63cd94
--- /dev/null
+++ b/pkg/trait/rest-dsl_test.go
@@ -0,0 +1,57 @@
+/*
+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/apis/camel/v1alpha1"
+
+       "github.com/stretchr/testify/assert"
+)
+
+func TestRestDslTraitApplicability(t *testing.T) {
+       e := &Environment{}
+
+       trait := newRestDslTrait()
+       enabled, err := trait.Configure(e)
+       assert.Nil(t, err)
+       assert.False(t, enabled)
+
+       e.Integration = &v1alpha1.Integration{
+               Status: v1alpha1.IntegrationStatus{
+                       Phase: v1alpha1.IntegrationPhaseNone,
+               },
+       }
+       enabled, err = trait.Configure(e)
+       assert.Nil(t, err)
+       assert.False(t, enabled)
+
+       resource := v1alpha1.ResourceSpec{
+               Type: v1alpha1.ResourceTypeOpenAPI,
+       }
+       e.Integration.Spec.Resources = append(e.Integration.Spec.Resources, 
resource)
+       enabled, err = trait.Configure(e)
+       assert.Nil(t, err)
+       assert.False(t, enabled)
+
+       e.Integration.Status.Phase = v1alpha1.IntegrationPhaseInitialization
+       enabled, err = trait.Configure(e)
+       assert.Nil(t, err)
+       assert.True(t, enabled)
+}
diff --git a/pkg/util/kubernetes/util.go b/pkg/util/kubernetes/util.go
index b55b56d..7f1df15 100644
--- a/pkg/util/kubernetes/util.go
+++ b/pkg/util/kubernetes/util.go
@@ -286,7 +286,7 @@ func GetConfigMapRefValue(ctx context.Context, client 
client.Client, namespace s
 // ResolveValueSource --
 func ResolveValueSource(ctx context.Context, client client.Client, namespace 
string, valueSource *v1alpha1.ValueSource) (string, error) {
        if valueSource.ConfigMapKeyRef != nil && valueSource.SecretKeyRef != 
nil {
-               return "", fmt.Errorf("value source has bot config map and 
secret configuired")
+               return "", fmt.Errorf("value source has bot config map and 
secret configured")
        }
        if valueSource.ConfigMapKeyRef != nil {
                return GetConfigMapRefValue(ctx, client, namespace, 
valueSource.ConfigMapKeyRef)

Reply via email to