Skip to content

Commit

Permalink
fix: Dependencies & rest-dsl traits are never enabled
Browse files Browse the repository at this point in the history
fixes #807
  • Loading branch information
jamesnetherton committed Jul 5, 2019
1 parent 4423046 commit 7e4afc8
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/trait/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
121 changes: 121 additions & 0 deletions pkg/trait/dependencies_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion pkg/trait/rest-dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
57 changes: 57 additions & 0 deletions pkg/trait/rest-dsl_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion pkg/util/kubernetes/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7e4afc8

Please sign in to comment.