From efe69d033d8745a69da67924c6749c468693a831 Mon Sep 17 00:00:00 2001 From: Robert Graeff Date: Thu, 20 Jun 2024 18:28:43 +0200 Subject: [PATCH] Unit tests (run-int-tests) --- pkg/landscaper/installations/context.go | 12 ++--- pkg/landscaper/installations/context_test.go | 50 ++++++++----------- .../executions/operation_test.go | 10 ++-- 3 files changed, 29 insertions(+), 43 deletions(-) diff --git a/pkg/landscaper/installations/context.go b/pkg/landscaper/installations/context.go index 9879efb3e9..0631b11a8f 100644 --- a/pkg/landscaper/installations/context.go +++ b/pkg/landscaper/installations/context.go @@ -8,21 +8,19 @@ import ( "context" "errors" "fmt" - cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2" - - "github.com/gardener/landscaper/pkg/utils" + cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2" apierrors "k8s.io/apimachinery/pkg/api/errors" "sigs.k8s.io/controller-runtime/pkg/client" + lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1" + lsv1alpha1helper "github.com/gardener/landscaper/apis/core/v1alpha1/helper" lserrors "github.com/gardener/landscaper/apis/errors" kutil "github.com/gardener/landscaper/controller-utils/pkg/kubernetes" "github.com/gardener/landscaper/controller-utils/pkg/logging" - "github.com/gardener/landscaper/pkg/components/model/componentoverwrites" - - lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1" - lsv1alpha1helper "github.com/gardener/landscaper/apis/core/v1alpha1/helper" lc "github.com/gardener/landscaper/controller-utils/pkg/logging/constants" + "github.com/gardener/landscaper/pkg/components/model/componentoverwrites" + "github.com/gardener/landscaper/pkg/utils" "github.com/gardener/landscaper/pkg/utils/read_write_layer" ) diff --git a/pkg/landscaper/installations/context_test.go b/pkg/landscaper/installations/context_test.go index e756d8b190..a7146cf46a 100644 --- a/pkg/landscaper/installations/context_test.go +++ b/pkg/landscaper/installations/context_test.go @@ -7,24 +7,20 @@ package installations_test import ( "context" - "github.com/open-component-model/ocm/pkg/contexts/datacontext" - "github.com/open-component-model/ocm/pkg/contexts/ocm" - - "github.com/gardener/landscaper/controller-utils/pkg/logging" - - "github.com/gardener/landscaper/apis/config" - cdv2 "github.com/gardener/component-spec/bindings-go/apis/v2" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/gstruct" + "github.com/open-component-model/ocm/pkg/contexts/datacontext" + "github.com/open-component-model/ocm/pkg/contexts/ocm" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/gardener/landscaper/apis/config" lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1" + "github.com/gardener/landscaper/controller-utils/pkg/logging" "github.com/gardener/landscaper/pkg/api" "github.com/gardener/landscaper/pkg/components/cnudie/componentresolvers" - "github.com/gardener/landscaper/pkg/components/model/componentoverwrites" "github.com/gardener/landscaper/pkg/components/registries" "github.com/gardener/landscaper/pkg/landscaper/installations" @@ -174,7 +170,7 @@ var _ = Describe("Context", func() { extCtx, err := installations.GetExternalContext(ctx, testenv.Client, inst) Expect(err).ToNot(HaveOccurred()) Expect(inst.Spec.ComponentDescriptor.Reference.RepositoryContext.Raw).To(MatchJSON(repoCtx.Raw)) - Expect(extCtx.RepositoryContext.Raw).To(MatchJSON(repoCtx.Raw)) + Expect(extCtx.ResultingRepositoryContext.Raw).To(MatchJSON(repoCtx.Raw)) }) It("should throw an error if a component name and version is defined but no repository context", func() { @@ -242,8 +238,10 @@ var _ = Describe("Context", func() { extCtx, err := installations.GetExternalContext(ctx, testenv.Client, inst) Expect(err).ToNot(HaveOccurred()) - Expect(cdv2.UnstructuredTypesEqual(inst.Spec.ComponentDescriptor.Reference.RepositoryContext, repoCtx)).To(BeTrue()) - Expect(cdv2.UnstructuredTypesEqual(extCtx.RepositoryContext, repoCtx)).To(BeTrue()) + // the installation should remain unchanged + Expect(cdv2.UnstructuredTypesEqual(inst.Spec.ComponentDescriptor.Reference.RepositoryContext, testutils.ExampleRepositoryContext())).To(BeTrue()) + // the resulting repository context should contain the result of the overwriting + Expect(cdv2.UnstructuredTypesEqual(extCtx.ResultingRepositoryContext, repoCtx)).To(BeTrue()) }) It("should overwrite a repository context defined by the external context", func() { @@ -287,8 +285,10 @@ var _ = Describe("Context", func() { extCtx, err := installations.GetExternalContext(ctx, testenv.Client, inst) Expect(err).ToNot(HaveOccurred()) - Expect(cdv2.UnstructuredTypesEqual(inst.Spec.ComponentDescriptor.Reference.RepositoryContext, repoCtx)).To(BeTrue()) - Expect(cdv2.UnstructuredTypesEqual(extCtx.RepositoryContext, repoCtx)).To(BeTrue()) + // the installation should remain unchanged + Expect(inst.Spec.ComponentDescriptor.Reference.RepositoryContext).To(BeNil()) + // the resulting repository context should contain the result of the overwriting + Expect(cdv2.UnstructuredTypesEqual(extCtx.ResultingRepositoryContext, repoCtx)).To(BeTrue()) }) }) @@ -314,20 +314,16 @@ var _ = Describe("Context", func() { Context("InjectComponentDescriptorRef", func() { It("should inject the component ref", func() { extCtx := installations.ExternalContext{ - Context: lsv1alpha1.Context{ - ContextConfiguration: lsv1alpha1.ContextConfiguration{ - RepositoryContext: testutils.ExampleRepositoryContext(), - }, - }, - ComponentName: "example.com/a", - ComponentVersion: "0.0.1", + ResultingRepositoryContext: testutils.ExampleRepositoryContext(), + ComponentName: "example.com/a", + ComponentVersion: "0.0.1", } inst := &lsv1alpha1.Installation{} extCtx.InjectComponentDescriptorRef(inst) Expect(inst.Spec.ComponentDescriptor).ToNot(BeNil()) Expect(inst.Spec.ComponentDescriptor.Reference).To(gstruct.PointTo(gstruct.MatchAllFields(gstruct.Fields{ - "RepositoryContext": Equal(extCtx.RepositoryContext), + "RepositoryContext": Equal(extCtx.ResultingRepositoryContext), "ComponentName": Equal("example.com/a"), "Version": Equal("0.0.1"), }))) @@ -335,13 +331,9 @@ var _ = Describe("Context", func() { It("should overwrite the component ref", func() { extCtx := installations.ExternalContext{ - Context: lsv1alpha1.Context{ - ContextConfiguration: lsv1alpha1.ContextConfiguration{ - RepositoryContext: testutils.ExampleRepositoryContext(), - }, - }, - ComponentName: "example.com/a", - ComponentVersion: "0.0.1", + ResultingRepositoryContext: testutils.ExampleRepositoryContext(), + ComponentName: "example.com/a", + ComponentVersion: "0.0.1", } inst := &lsv1alpha1.Installation{} @@ -354,7 +346,7 @@ var _ = Describe("Context", func() { extCtx.InjectComponentDescriptorRef(inst) Expect(inst.Spec.ComponentDescriptor).ToNot(BeNil()) Expect(inst.Spec.ComponentDescriptor.Reference).To(gstruct.PointTo(gstruct.MatchAllFields(gstruct.Fields{ - "RepositoryContext": Equal(extCtx.RepositoryContext), + "RepositoryContext": Equal(extCtx.ResultingRepositoryContext), "ComponentName": Equal("example.com/a"), "Version": Equal("0.0.1"), }))) diff --git a/pkg/landscaper/installations/executions/operation_test.go b/pkg/landscaper/installations/executions/operation_test.go index ea333d2370..e25fdcc4ee 100644 --- a/pkg/landscaper/installations/executions/operation_test.go +++ b/pkg/landscaper/installations/executions/operation_test.go @@ -82,13 +82,9 @@ var _ = Describe("Execution Operation", func() { Name: "default", Parent: nil, External: installations.ExternalContext{ - Context: lsv1alpha1.Context{ - ContextConfiguration: lsv1alpha1.ContextConfiguration{ - RepositoryContext: &repositoryContext, - }, - }, - ComponentName: "example.com/root", - ComponentVersion: "v1.0.0", + ResultingRepositoryContext: &repositoryContext, + ComponentName: "example.com/root", + ComponentVersion: "v1.0.0", }, }