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

[camel-k] 03/03: Fix #2530: fix test to check actual resources on the namespace

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 f168d646a79949de404a20d334472d283ad9b07d
Author: nicolaferraro <ni...@gmail.com>
AuthorDate: Thu Jul 29 13:46:46 2021 +0200

    Fix #2530: fix test to check actual resources on the namespace
---
 pkg/resources/resources.go    |  4 ++--
 pkg/trait/pull_secret_test.go | 45 +++++++++++++++++++++++++++++--------------
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index f1acd00..ee2eb30 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -467,9 +467,9 @@ var assets = func() http.FileSystem {
 		"/traits.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "traits.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 38723,
+			uncompressedSize: 39017,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\x7b\x73\x1c\xb9\xf1\xd8\xff\xfa\x14\x28\xfe\x52\xc5\x47\xed\x0e\xa9\x73\x6c\x5f\x98\x28\x2e\x9e\xa4\xb3\x79\xa7\x07\x23\xca\xe7\x4a\x29\x57\x5e\xec\x4c\xef\x2e\x44\x0c\x30\x06\x30\xa4\xd6\xa9\x7c\xf7\x14\xba\xf1\x9a\xdd\x21\xb9\xd4\x1d\xaf\x8e\xa9\xd8\x7f\x9c\x48\xce\x34\x1a\x8d\x46\xbf\xbb\xc7\x19\x2e\x9c\x3d\x7d\x36\x65\x8a\xb7\x70\xca\xf8\x62\x21\x94\x70\xeb\x67\x8c\x75\x92\xbb\x85\x36\xed\x29\x5b\x70\x69\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\x7b\x73\x1c\x37\xf2\xd8\xff\xfa\x14\x28\xfe\x52\xc5\x47\xed\x0c\x29\x5f\xee\xce\x61\xa2\x5c\xd1\x92\x7c\xa6\xad\x07\x23\xf2\x7c\x95\x52\x54\xb7\xd8\x99\xde\x5d\x88\x33\xc0\x1c\x80\x21\xb5\x4e\xe5\xbb\xa7\xd0\x8d\xd7\xec\x0e\x97\x4b\xd9\x74\x99\xa9\xdc\xfd\x61\x91\x9c\x01\x1a\x8d\x7e\xbf\xc6\x6a\x2e\xac\x39\x7d\x56\x30\xc9\x5b\x38\x65\x7c\x3e\x17\x52\xd8\xd5\x33\xc6\xba\x86\xdb\xb9\xd2\xed\x29\x9b\xf3\xc6\x80\x [...]
 		},
 	}
 	fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
diff --git a/pkg/trait/pull_secret_test.go b/pkg/trait/pull_secret_test.go
index 9efe192..44ee3ef 100644
--- a/pkg/trait/pull_secret_test.go
+++ b/pkg/trait/pull_secret_test.go
@@ -18,19 +18,23 @@ limitations under the License.
 package trait
 
 import (
-	"strings"
+	"context"
 	"testing"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/test"
 	appsv1 "k8s.io/api/apps/v1"
 	corev1 "k8s.io/api/core/v1"
+	rbacv1 "k8s.io/api/rbac/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	"github.com/stretchr/testify/assert"
 )
 
 func TestPullSecret(t *testing.T) {
-	e, deployment := getEnvironmentAndDeployment()
+	e, deployment := getEnvironmentAndDeployment(t)
 
 	trait := newPullSecretTrait().(*pullSecretTrait)
 	trait.SecretName = "xxxy"
@@ -44,7 +48,7 @@ func TestPullSecret(t *testing.T) {
 }
 
 func TestPullSecretDoesNothingWhenNotSetOnPlatform(t *testing.T) {
-	e, _ := getEnvironmentAndDeployment()
+	e, _ := getEnvironmentAndDeployment(t)
 	e.Platform = &v1.IntegrationPlatform{}
 
 	trait := newPullSecretTrait()
@@ -54,7 +58,7 @@ func TestPullSecretDoesNothingWhenNotSetOnPlatform(t *testing.T) {
 }
 
 func TestPullSecretAuto(t *testing.T) {
-	e, _ := getEnvironmentAndDeployment()
+	e, _ := getEnvironmentAndDeployment(t)
 
 	trait := newPullSecretTrait().(*pullSecretTrait)
 	trait.Auto = newFalse()
@@ -64,7 +68,7 @@ func TestPullSecretAuto(t *testing.T) {
 }
 
 func TestPullSecretImagePullerDelegation(t *testing.T) {
-	e, _ := getEnvironmentAndDeployment()
+	e, _ := getEnvironmentAndDeployment(t)
 
 	trait := newPullSecretTrait().(*pullSecretTrait)
 	trait.Auto = newFalse()
@@ -75,27 +79,35 @@ func TestPullSecretImagePullerDelegation(t *testing.T) {
 	assert.True(t, *trait.ImagePullerDelegation)
 
 	err = trait.Apply(e)
-	assert.Nil(t, err)
+	assert.NoError(t, err)
 
-	found := false
-	for _, item := range e.Resources.Items() {
-		found = strings.HasPrefix(item.GetName(), "camel-k-puller")
-		if found {
-			break
-		}
+	var roleBinding rbacv1.RoleBinding
+	roleBindingKey := client.ObjectKey{
+		Namespace: "test",
+		Name:      "camel-k-puller-test-default",
 	}
-	assert.True(t, found)
+	err = e.Client.Get(e.C, roleBindingKey, &roleBinding)
+	assert.NoError(t, err)
+	assert.Len(t, roleBinding.Subjects, 1)
 }
 
-func getEnvironmentAndDeployment() (*Environment, *appsv1.Deployment) {
+func getEnvironmentAndDeployment(t *testing.T) (*Environment, *appsv1.Deployment) {
 	e := &Environment{}
 	e.Integration = &v1.Integration{
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: "test",
+			Name:      "myit",
+		},
 		Status: v1.IntegrationStatus{
 			Phase: v1.IntegrationPhaseDeploying,
 		},
 	}
 
 	deployment := appsv1.Deployment{
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: "test",
+			Name:      "myit",
+		},
 		Spec: appsv1.DeploymentSpec{
 			Template: corev1.PodTemplateSpec{
 				Spec: corev1.PodSpec{},
@@ -104,6 +116,11 @@ func getEnvironmentAndDeployment() (*Environment, *appsv1.Deployment) {
 	}
 	e.Resources = kubernetes.NewCollection(&deployment)
 
+	var err error
+	e.C = context.TODO()
+	e.Client, err = test.NewFakeClient(e.Integration, &deployment)
+	assert.NoError(t, err)
+
 	return e, &deployment
 }