This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit a9242cfe223c202253820428dee49a5344394845 Author: Antonin Stefanutti <[email protected]> AuthorDate: Fri Sep 3 10:15:32 2021 +0200 feat(native): Add builder native e2e test --- e2e/builder/build_test.go | 42 +++++++++++++++++++++++++++++-------- e2e/support/test_support.go | 50 +++++++++++++++++++++++++++++++-------------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/e2e/builder/build_test.go b/e2e/builder/build_test.go index 737647e..8419950 100644 --- a/e2e/builder/build_test.go +++ b/e2e/builder/build_test.go @@ -30,25 +30,51 @@ import ( "github.com/apache/camel-k/pkg/apis/camel/v1" ) +type kitOptions struct { + dependencies []string + traits []string +} + func TestKitTimerToLogFullBuild(t *testing.T) { - doKitFullBuild(t, "timer-to-log", "camel:timer", "camel:log") + doKitFullBuild(t, "timer-to-log", kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + }) } func TestKitKnativeFullBuild(t *testing.T) { - doKitFullBuild(t, "knative", "camel:knative") + doKitFullBuild(t, "knative", kitOptions{ + dependencies: []string{ + "camel:knative", + }, + }) } -func doKitFullBuild(t *testing.T, name string, dependencies ...string) { +func TestKitTimerToLogFullNativeBuild(t *testing.T) { + doKitFullBuild(t, "timer-to-log", kitOptions{ + dependencies: []string{ + "camel:timer", "camel:log", + }, + traits: []string{ + "quarkus.package-type=native", + }, + }) +} + +func doKitFullBuild(t *testing.T, name string, options kitOptions) { WithNewTestNamespace(t, func(ns string) { Expect(Kamel("install", "-n", ns).Execute()).To(Succeed()) buildKitArgs := []string{"kit", "create", name, "-n", ns} - for _, dep := range dependencies { - buildKitArgs = append(buildKitArgs, "-d", dep) + for _, dependency := range options.dependencies { + buildKitArgs = append(buildKitArgs, "-d", dependency) + } + for _, trait := range options.traits { + buildKitArgs = append(buildKitArgs, "-t", trait) } Expect(Kamel(buildKitArgs...).Execute()).To(Succeed()) Eventually(Build(ns, name)).ShouldNot(BeNil()) - Eventually(func() v1.BuildPhase { - return Build(ns, name)().Status.Phase - }, TestTimeoutMedium).Should(Equal(v1.BuildPhaseSucceeded)) + Eventually(BuildPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.BuildPhaseSucceeded)) + Eventually(KitPhase(ns, name), TestTimeoutMedium).Should(Equal(v1.IntegrationKitPhaseReady)) }) } diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index a85b0d4..6f29b22 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -26,7 +26,6 @@ import ( "bytes" "context" "encoding/json" - "errors" "fmt" "io" "io/ioutil" @@ -36,11 +35,9 @@ import ( "testing" "time" - "github.com/apache/camel-k/pkg/util/patch" "github.com/google/uuid" "github.com/onsi/gomega" "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/types" appsv1 "k8s.io/api/apps/v1" "k8s.io/api/batch/v1beta1" @@ -49,6 +46,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" "k8s.io/utils/pointer" ctrl "sigs.k8s.io/controller-runtime/pkg/client" @@ -70,6 +68,7 @@ import ( "github.com/apache/camel-k/pkg/util/kubernetes" "github.com/apache/camel-k/pkg/util/log" "github.com/apache/camel-k/pkg/util/openshift" + "github.com/apache/camel-k/pkg/util/patch" // let's enable addons in all tests _ "github.com/apache/camel-k/addons" @@ -569,6 +568,28 @@ func IntegrationKit(ns string, name string) func() string { } } +func Kit(ns, name string) func() *v1.IntegrationKit { + return func() *v1.IntegrationKit { + kit := v1.NewIntegrationKit(ns, name) + if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(kit), kit); err != nil && !k8serrors.IsNotFound(err) { + panic(err) + } else if err != nil && k8serrors.IsNotFound(err) { + return nil + } + return kit + } +} + +func KitPhase(ns, name string) func() v1.IntegrationKitPhase { + return func() v1.IntegrationKitPhase { + kit := Kit(ns, name)() + if kit == nil { + return v1.IntegrationKitPhaseNone + } + return kit.Status.Phase + } +} + func UpdateIntegration(ns string, name string, upd func(it *v1.Integration)) error { it := Integration(ns, name)() if it == nil { @@ -851,7 +872,7 @@ func DeploymentCondition(ns string, name string, conditionType appsv1.Deployment } } -func Build(ns string, name string) func() *v1.Build { +func Build(ns, name string) func() *v1.Build { return func() *v1.Build { build := v1.NewBuild(ns, name) if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(build), build); err != nil && k8serrors.IsNotFound(err) { @@ -864,6 +885,16 @@ func Build(ns string, name string) func() *v1.Build { } } +func BuildPhase(ns, name string) func() v1.BuildPhase { + return func() v1.BuildPhase { + build := Build(ns, name)() + if build != nil { + return build.Status.Phase + } + return v1.BuildPhaseNone + } +} + func Platform(ns string) func() *v1.IntegrationPlatform { return func() *v1.IntegrationPlatform { lst := v1.NewIntegrationPlatformList() @@ -894,17 +925,6 @@ func DeletePlatform(ns string) func() bool { } } -func SetPlatformVersion(ns string, version string) func() error { - return func() error { - p := Platform(ns)() - if p == nil { - return errors.New("no platform found") - } - p.Status.Version = version - return TestClient().Status().Update(TestContext, p) - } -} - func PlatformVersion(ns string) func() string { return func() string { p := Platform(ns)()
