github.com/verrazzano/verrazzano@v1.7.0/tools/vz/test/helpers/assertions.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package helpers
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/verrazzano/verrazzano/tools/vz/pkg/constants"
    12  	appsv1 "k8s.io/api/apps/v1"
    13  	corev1 "k8s.io/api/core/v1"
    14  	"sigs.k8s.io/controller-runtime/pkg/client"
    15  )
    16  
    17  // AssertPrivateRegistryEnvVars asserts that the deployment container has the expected private registry environment variables
    18  func AssertPrivateRegistryEnvVars(t *testing.T, client client.Client, deployment *appsv1.Deployment, expectedImageRegistry, expectedImagePrefix string) {
    19  	envVar := corev1.EnvVar{Name: "REGISTRY", Value: expectedImageRegistry}
    20  	assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Env, envVar)
    21  	envVar = corev1.EnvVar{Name: "IMAGE_REPO", Value: expectedImagePrefix}
    22  	assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Env, envVar)
    23  }
    24  
    25  // AssertPrivateRegistryImage asserts that the deployment container and init container VPO images have the correct registry and prefix for private registry
    26  func AssertPrivateRegistryImage(t *testing.T, client client.Client, deployment *appsv1.Deployment, expectedImageRegistry, expectedImagePrefix string) {
    27  	vpoRepo := expectedImageRegistry + "/" + expectedImagePrefix + "/verrazzano/" + constants.VerrazzanoPlatformOperator
    28  	assert.True(t, strings.HasPrefix(deployment.Spec.Template.Spec.InitContainers[0].Image, vpoRepo),
    29  		"Expected container image %s to start with %s", deployment.Spec.Template.Spec.InitContainers[0].Image, vpoRepo)
    30  	assert.True(t, strings.HasPrefix(deployment.Spec.Template.Spec.Containers[0].Image, vpoRepo),
    31  		"Expected init container image %s to start with %s", deployment.Spec.Template.Spec.InitContainers[0].Image, vpoRepo)
    32  }