You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/02/24 10:35:55 UTC

[camel-k] branch main updated: [TEST] Add CliDownloadTest

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 35c2126  [TEST] Add CliDownloadTest
35c2126 is described below

commit 35c2126890f8f08adb411ec36574267f196c36b1
Author: Jan Bouska <jb...@redhat.com>
AuthorDate: Fri Feb 11 14:08:50 2022 +0100

    [TEST] Add CliDownloadTest
---
 e2e/common/cli/install_test.go | 63 ++++++++++++++++++++++++++++++++++++++++++
 e2e/support/test_support.go    | 16 +++++++++--
 e2e/support/test_util.go       | 10 +++++++
 3 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/e2e/common/cli/install_test.go b/e2e/common/cli/install_test.go
index 8d99b78..bfe1bae 100644
--- a/e2e/common/cli/install_test.go
+++ b/e2e/common/cli/install_test.go
@@ -23,7 +23,17 @@ limitations under the License.
 package common
 
 import (
+	"bytes"
+	"github.com/apache/camel-k/pkg/install"
+	"github.com/apache/camel-k/pkg/util/defaults"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/openshift"
+	console "github.com/openshift/api/console/v1"
+	"github.com/stretchr/testify/assert"
+	"reflect"
+	"strings"
 	"testing"
+	"text/template"
 
 	. "github.com/onsi/gomega"
 
@@ -77,6 +87,59 @@ func TestSkipRegistryInstallation(t *testing.T) {
 	})
 }
 
+type templateArgs struct {
+	Version  string
+	Platform string
+}
+
+func TestConsoleCliDownload(t *testing.T) {
+	ocp, err := openshift.IsOpenShift(TestClient())
+	assert.Nil(t, err)
+
+	ok, err := kubernetes.IsAPIResourceInstalled(TestClient(), "console.openshift.io/v1", reflect.TypeOf(console.ConsoleCLIDownload{}).Name())
+	assert.Nil(t, err)
+
+	if !ocp || !ok {
+		t.Skip("This test requires ConsoleCliDownload object which is available on OpenShift 4 only.")
+		return
+	}
+
+	name := GetEnvOrDefault("CAMEL_K_CONSOLE_CLI_DOWNLOAD_NAME", install.KamelCLIDownloadName)
+	downloadUrlTemplate := GetEnvOrDefault("CAMEL_K_CONSOLE_CLI_DOWNLOAD_URL_TEMPLATE", "https://github.com/apache/camel-k/releases/download/v{{ .Version}}/camel-k-client-{{ .Version}}-{{ .Platform}}-64bit.tar.gz")
+
+	args := templateArgs{Version: defaults.Version}
+	templt, err := template.New("downloadLink").Parse(downloadUrlTemplate)
+	assert.Nil(t, err)
+
+	WithNewTestNamespace(t, func(ns string) {
+		// make sure there is no preinstalled CliDownload resource
+		cliDownload := ConsoleCLIDownload(name)()
+		if cliDownload != nil {
+			Expect(TestClient().Delete(TestContext, cliDownload)).To(Succeed())
+		}
+
+		Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+		Eventually(ConsoleCLIDownload(name), TestTimeoutMedium).Should(Not(BeNil()))
+
+		cliDownload = ConsoleCLIDownload(name)()
+		links := cliDownload.Spec.Links
+
+		for _, link := range links {
+			var buf bytes.Buffer
+			if strings.Contains(link.Text, "for Linux") {
+				args.Platform = "linux"
+			} else if strings.Contains(link.Text, "for Mac") {
+				args.Platform = "mac"
+			} else if strings.Contains(link.Text, "for Windows") {
+				args.Platform = "windows"
+			}
+
+			templt.Execute(&buf, args)
+			Expect(link.Href).To(MatchRegexp(buf.String()))
+		}
+	})
+}
+
 func TestInstallSkipDefaultKameletsInstallation(t *testing.T) {
 	WithNewTestNamespace(t, func(ns string) {
 		Expect(Kamel("install", "-n", ns, "--skip-default-kamelets-setup").Execute()).To(Succeed())
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index 4c856b1..9649525 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -28,6 +28,8 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
+	consoleV1 "github.com/openshift/api/console/v1"
+	"github.com/stretchr/testify/assert"
 	"io"
 	"io/ioutil"
 	"os"
@@ -42,8 +44,6 @@ import (
 	"github.com/onsi/gomega/format"
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
-	"github.com/stretchr/testify/assert"
-
 	appsv1 "k8s.io/api/apps/v1"
 	"k8s.io/api/batch/v1beta1"
 	coordination "k8s.io/api/coordination/v1"
@@ -1223,6 +1223,18 @@ func CRDs() func() []metav1.APIResource {
 	}
 }
 
+func ConsoleCLIDownload(name string) func() *consoleV1.ConsoleCLIDownload {
+	return func() *consoleV1.ConsoleCLIDownload {
+		cliDownload := consoleV1.ConsoleCLIDownload{}
+		if err := TestClient().Get(TestContext, ctrl.ObjectKey{Name: name}, &cliDownload); err != nil && !k8serrors.IsNotFound(err) {
+			panic(err)
+		} else if err != nil && k8serrors.IsNotFound(err) {
+			return nil
+		}
+		return &cliDownload
+	}
+}
+
 func OperatorPod(ns string) func() *corev1.Pod {
 	return func() *corev1.Pod {
 		lst := corev1.PodList{
diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go
index d95599c..2b8cc31 100644
--- a/e2e/support/test_util.go
+++ b/e2e/support/test_util.go
@@ -25,6 +25,7 @@ package support
 import (
 	. "github.com/onsi/gomega"
 	. "github.com/onsi/gomega/gstruct"
+	"os"
 
 	"github.com/onsi/gomega/types"
 )
@@ -36,3 +37,12 @@ func EqualP(expected interface{}) types.GomegaMatcher {
 func MatchFieldsP(options Options, fields Fields) types.GomegaMatcher {
 	return PointTo(MatchFields(options, fields))
 }
+
+func GetEnvOrDefault(key string, deflt string) string {
+	env, exists := os.LookupEnv(key)
+	if exists {
+		return env
+	} else {
+		return deflt
+	}
+}