Skip to content

Commit

Permalink
Add test case for old moduletemplate name with modulereleasemeta
Browse files Browse the repository at this point in the history
  • Loading branch information
nesmabadr committed Oct 15, 2024
1 parent 9fb6de1 commit e6a4c77
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ runs:
kubectl apply -f mrm.yaml
- name: Apply ModuleReleaseMeta with old ModuleTemplate name
working-directory: template-operator
if: ${{ matrix.e2e-test == 'modulereleasemeta-with-old-moduletemplate-name' }}
}}
shell: bash
run: |
make build-manifests
kyma alpha create module --module-config-file ./module-config.yaml --path . --registry localhost:5111 --insecure
sed -i 's/localhost:5111/k3d-kcp-registry.localhost:5000/g' ./template.yaml
kubectl apply -f template.yaml
kubectl apply -f module-release-meta.yaml

1 change: 1 addition & 0 deletions .github/workflows/test-e2e-with-modulereleasemeta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- misconfigured-kyma-secret
- rbac-privileges
- ocm-compatible-module-template
- modulereleasemeta-with-old-moduletemplate-name
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand Down
18 changes: 18 additions & 0 deletions pkg/testutils/kyma.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
ErrContainsUnexpectedModules = errors.New("kyma CR contains unexpected modules")
ErrNotContainsExpectedModules = errors.New("kyma CR not contains expected modules")
ErrModuleVersionInStatusIsIncorrect = errors.New("status.modules.version is incorrect")
ErrModuleMessageInStatusIsIncorrect = errors.New("status.modules.message is incorrect")
)

func NewTestKyma(name string) *v1beta2.Kyma {
Expand Down Expand Up @@ -357,6 +358,23 @@ func ContainsModuleInSpec(ctx context.Context,
return ErrNotContainsExpectedModules
}

func ModuleMessageInKymaStatusIsCorrect(ctx context.Context, clnt client.Client,
kymaName, kymaNamespace, moduleName, message string,
) error {
kyma, err := GetKyma(ctx, clnt, kymaName, kymaNamespace)
if err != nil {
return err
}

for _, module := range kyma.Status.Modules {
if module.Name == moduleName && module.Message == message {
return nil
}
}

return ErrModuleMessageInStatusIsIncorrect
}

func ModuleVersionInKymaStatusIsCorrect(ctx context.Context,
clnt client.Client, kymaName, kymaNamespace, moduleName, moduleVersion string,
) error {
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,7 @@ rbac-privileges:
go test -timeout 20m -ginkgo.v -ginkgo.focus "RBAC Privileges"

ocm-compatible-module-template:
go test -timeout 20m -ginkgo.v -ginkgo.focus "OCM Format Module Template"
go test -timeout 20m -ginkgo.v -ginkgo.focus "OCM Format Module Template"

modulereleasemeta-with-old-moduletemplate-name:
go test -timeout 20m -ginkgo.v -ginkgo.focus "ModuleReleaseMeta With Old ModuleTemplate Name"
50 changes: 50 additions & 0 deletions tests/e2e/modulereleasemeta_with_old_moduletemplate_name_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package e2e_test

import (
"fmt"

"github.com/kyma-project/lifecycle-manager/api/shared"
"github.com/kyma-project/lifecycle-manager/api/v1beta2"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/kyma-project/lifecycle-manager/pkg/testutils"
)

var _ = Describe("ModuleReleaseMeta With Old ModuleTemplate Name", Ordered, func() {
kyma := NewKymaWithSyncLabel("kyma-sample", ControlPlaneNamespace, v1beta2.DefaultChannel)
module := NewTemplateOperator(v1beta2.DefaultChannel)

expectedErrorMessage := fmt.Sprintf("failed to get module template: ModuleTemplate.operator.kyma-project.io %s-%s not found",
module.Name, "1.0.0")

InitEmptyKymaBeforeAll(kyma)
CleanupKymaAfterAll(kyma)

Context("Given kyma deployed in KCP", func() {
It("When enabling Template Operator", func() {
Eventually(EnableModule).
WithContext(ctx).
WithArguments(skrClient, defaultRemoteKymaName, RemoteNamespace, module).
Should(Succeed())
})

It("Then KCP Kyma CR is in \"Error\" State", func() {
Eventually(KymaIsInState).
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), kcpClient, shared.StateError).
Should(Succeed())
Consistently(KymaIsInState).
WithContext(ctx).
WithArguments(kyma.GetName(), kyma.GetNamespace(), kcpClient, shared.StateError).
Should(Succeed())

By("And Module Message in Kyma Status is as expected")
Eventually(ModuleMessageInKymaStatusIsCorrect).
WithContext(ctx).
WithArguments(kcpClient, kyma.GetName(), kyma.GetNamespace(), module.Name, expectedErrorMessage).
Should(Succeed())
})
})
})

0 comments on commit e6a4c77

Please sign in to comment.