Skip to content

Commit

Permalink
Unit tests (run-int-tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgraeff committed Jun 20, 2024
1 parent 95eb8dd commit efe69d0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 deletions.
12 changes: 5 additions & 7 deletions pkg/landscaper/installations/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
50 changes: 21 additions & 29 deletions pkg/landscaper/installations/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
})
})

Expand All @@ -314,34 +314,26 @@ 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"),
})))
})

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{}
Expand All @@ -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"),
})))
Expand Down
10 changes: 3 additions & 7 deletions pkg/landscaper/installations/executions/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down

0 comments on commit efe69d0

Please sign in to comment.