Skip to content

Commit

Permalink
Fix apache#1047: mark platform as generated and add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Dec 4, 2019
1 parent ced9405 commit 83b69de
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
57 changes: 57 additions & 0 deletions e2e/platformless_run_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 e2e

import (
"testing"
"time"

"github.com/apache/camel-k/pkg/util/openshift"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
)

func TestPlatformlessRun(t *testing.T) {
ocp, err := openshift.IsOpenShift(testClient)
assert.Nil(t, err)
if !ocp {
t.Skip("This test is for OpenShift only")
return
}

withNewTestNamespace(func(ns string) {
RegisterTestingT(t)
Expect(kamel("install", "-n", ns).Execute()).Should(BeNil())

// Delete the platform from the namespace before running the integration
Eventually(deletePlatform(ns)).Should(BeTrue())

Expect(kamel("run", "-n", ns, "files/yaml.yaml").Execute()).Should(BeNil())
Eventually(integrationPodPhase(ns, "yaml"), 5*time.Minute).Should(Equal(v1.PodRunning))
Eventually(integrationLogs(ns, "yaml"), 1*time.Minute).Should(ContainSubstring("Magicstring!"))

// Platform should be recreated
Eventually(platform(ns)).ShouldNot(BeNil())
Expect(kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
})
}
14 changes: 14 additions & 0 deletions e2e/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ func platform(ns string) func() *v1alpha1.IntegrationPlatform {
}
}

func deletePlatform(ns string) func() bool {
return func() bool {
pl := platform(ns)()
if pl == nil {
return true
}
err := testClient.Delete(testContext, pl)
if err != nil {
log.Error(err, "Got error while deleting the platform")
}
return false
}
}

func setPlatformVersion(ns string, version string) error {
p := platform(ns)()
if p == nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/trait/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (t *platformTrait) getOrCreatePlatform(e *Environment) (*v1alpha1.Integrati
platformName = platform.DefaultPlatformName
}
defaultPlatform := v1alpha1.NewIntegrationPlatform(e.Integration.Namespace, platformName)
if defaultPlatform.Labels == nil {
defaultPlatform.Labels = make(map[string]string)
}
defaultPlatform.Labels["camel.apache.org/platform.generated"] = True
pl = &defaultPlatform
e.Resources.Add(pl)
return pl, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/trait/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestPlatformTraitCreatesDefaultPlatform(t *testing.T) {
assert.Equal(t, v1alpha1.IntegrationPhaseWaitingForPlatform, e.Integration.Status.Phase)
assert.Equal(t, 1, len(e.Resources.Items()))
defPlatform := v1alpha1.NewIntegrationPlatform("ns1", platform.DefaultPlatformName)
defPlatform.Labels = map[string]string{"camel.apache.org/platform.generated": True}
assert.Contains(t, e.Resources.Items(), &defPlatform)
}

Expand Down

0 comments on commit 83b69de

Please sign in to comment.