Let's connect
Let's connect

Cloud infrastructure end-to-end or conformance testing: What’s the difference

Picture of Sylwia Brant, Cloud Engineer

Sylwia Brant

Cloud Engineer

13 minutes read

How to evaluate cloud-native technology and build trust
3-1

bash

func TestJobPullFromACR(t *testing.T) {
	f := features.New("Pull from ACR").
		Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
			var err error
			ctx, err = createNSForTest(ctx, cfg, t)
			require.NoError(t, err)
			namespace := fmt.Sprint(ctx.Value(contextNamespaceNameKey))

			t.Logf("Creating pod with testing image")
			pod := buildPullACRImagePod(namespace)
			assert.NoError(t, cfg.Client().Resources(namespace).Create(ctx, pod))

			t.Logf("Pod %s/%s scheduled", namespace, podName)

			return ctx
		}).
		Assess("Pull image from ACR", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
			namespace := fmt.Sprint(ctx.Value(contextNamespaceNameKey))

			pod := &corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: podName, Namespace: namespace}}
			err := wait.For(conditions.New(cfg.Client().Resources()).PodRunning(pod), wait.WithImmediate(), wait.WithTimeout(time.Minute), wait.WithInterval(time.Second))
			if assert.NoError(t, err) {
				t.Logf("Pod reached phase 'Running'")
			} else {
				t.Logf("Pod didn't reach phase 'Running': %s", err.Error())
			}

			return ctx
		}).Teardown(func(ctx context.Context, t *testing.T, config *envconf.Config) context.Context {
		assert.NoError(t, deleteNSForTest(ctx, config, t))
		return ctx
	}).Feature()

	testEnvironment.Test(t, f)
}

func buildPullACRImagePod(namespaceName string) *corev1.Pod {
	acrName := buildAzureResourceNameWithoutHyphens("eun", "containerregistry")
	return &corev1.Pod{
		ObjectMeta: metav1.ObjectMeta{
			Name:      podName,
			Namespace: namespaceName,
		},
		Spec: corev1.PodSpec{
			Containers: []corev1.Container{
				{
					Name:  "pull-from-acr-container",
					Image: fmt.Sprintf("%s.azurecr.io/conformance-testing:latest", acrName),
				},
			},
		},
	}
}
graphics

Liked the article?

Share it with others!

explore more on

Take the first step to a sustained competitive edge for your business

Get your free consultation

VirtusLab's work has met the mark several times over, and their latest project is no exception. The team is efficient, hard-working, and trustworthy. Customers can expect a proactive team that drives results.

Stephen Rooke
Stephen RookeDirector of Software Development @ Extreme Reach

VirtusLab's engineers are truly Strapi extensions experts. Their knowledge and expertise in the area of Strapi plugins gave us the opportunity to lift our multi-brand CMS implementation to a different level.

facile logo
Leonardo PoddaEngineering Manager @ Facile.it

VirtusLab has been an incredible partner since the early development of Scala 3, essential to a mature and stable Scala 3 ecosystem.

Martin_Odersky
Martin OderskyHead of Programming Research Group @ EPFL

The VirtusLab team's in-depth knowledge, understanding, and experience of technology have been invaluable to us in developing our product. The team is professional and delivers on time – we greatly appreciated this efficiency when working with them.

Michael_Grant
Michael GrantDirector of Development @ Cyber Sec Company