You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/07/16 10:48:55 UTC

[camel-k] branch main updated: chore(trait): pull-secret unit test

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

nferraro 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 95827bd  chore(trait): pull-secret unit test
95827bd is described below

commit 95827bdffa7b8b67b5813a3c20e644189763bc17
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Wed Jul 14 11:42:33 2021 +0200

    chore(trait): pull-secret unit test
---
 pkg/trait/pull_secret_test.go | 77 ++++++++++++++++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 20 deletions(-)

diff --git a/pkg/trait/pull_secret_test.go b/pkg/trait/pull_secret_test.go
index a1499e0..9efe192 100644
--- a/pkg/trait/pull_secret_test.go
+++ b/pkg/trait/pull_secret_test.go
@@ -18,6 +18,7 @@ limitations under the License.
 package trait
 
 import (
+	"strings"
 	"testing"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
@@ -29,21 +30,7 @@ import (
 )
 
 func TestPullSecret(t *testing.T) {
-	e := &Environment{}
-	e.Integration = &v1.Integration{
-		Status: v1.IntegrationStatus{
-			Phase: v1.IntegrationPhaseDeploying,
-		},
-	}
-
-	deployment := appsv1.Deployment{
-		Spec: appsv1.DeploymentSpec{
-			Template: corev1.PodTemplateSpec{
-				Spec: corev1.PodSpec{},
-			},
-		},
-	}
-	e.Resources = kubernetes.NewCollection(&deployment)
+	e, deployment := getEnvironmentAndDeployment()
 
 	trait := newPullSecretTrait().(*pullSecretTrait)
 	trait.SecretName = "xxxy"
@@ -57,13 +44,56 @@ func TestPullSecret(t *testing.T) {
 }
 
 func TestPullSecretDoesNothingWhenNotSetOnPlatform(t *testing.T) {
+	e, _ := getEnvironmentAndDeployment()
+	e.Platform = &v1.IntegrationPlatform{}
+
+	trait := newPullSecretTrait()
+	enabled, err := trait.Configure(e)
+	assert.Nil(t, err)
+	assert.False(t, enabled)
+}
+
+func TestPullSecretAuto(t *testing.T) {
+	e, _ := getEnvironmentAndDeployment()
+
+	trait := newPullSecretTrait().(*pullSecretTrait)
+	trait.Auto = newFalse()
+	enabled, err := trait.Configure(e)
+	assert.Nil(t, err)
+	assert.False(t, enabled)
+}
+
+func TestPullSecretImagePullerDelegation(t *testing.T) {
+	e, _ := getEnvironmentAndDeployment()
+
+	trait := newPullSecretTrait().(*pullSecretTrait)
+	trait.Auto = newFalse()
+	trait.ImagePullerDelegation = newTrue()
+	enabled, err := trait.Configure(e)
+	assert.Nil(t, err)
+	assert.True(t, enabled)
+	assert.True(t, *trait.ImagePullerDelegation)
+
+	err = trait.Apply(e)
+	assert.Nil(t, err)
+
+	found := false
+	for _, item := range e.Resources.Items() {
+		found = strings.HasPrefix(item.GetName(), "camel-k-puller")
+		if found {
+			break
+		}
+	}
+	assert.True(t, found)
+}
+
+func getEnvironmentAndDeployment() (*Environment, *appsv1.Deployment) {
 	e := &Environment{}
 	e.Integration = &v1.Integration{
 		Status: v1.IntegrationStatus{
 			Phase: v1.IntegrationPhaseDeploying,
 		},
 	}
-	e.Platform = &v1.IntegrationPlatform{}
 
 	deployment := appsv1.Deployment{
 		Spec: appsv1.DeploymentSpec{
@@ -74,8 +104,15 @@ func TestPullSecretDoesNothingWhenNotSetOnPlatform(t *testing.T) {
 	}
 	e.Resources = kubernetes.NewCollection(&deployment)
 
-	trait := newPullSecretTrait()
-	enabled, err := trait.Configure(e)
-	assert.Nil(t, err)
-	assert.False(t, enabled)
+	return e, &deployment
+}
+
+func newFalse() *bool {
+	b := false
+	return &b
+}
+
+func newTrue() *bool {
+	b := true
+	return &b
 }