From 9207f2cd6836e50c3ea320b0cbe6c5fff47d9bcd Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Mon, 4 Nov 2024 09:05:36 +0100 Subject: [PATCH] add e2e testcases --- tests/e2e/create/create_suite_test.go | 27 +++++---- tests/e2e/create/create_test.go | 56 +++++++++++++++++++ .../moduleconfig/invalid/duplicate-icons.yaml | 13 +++++ .../invalid/icons-without-link.yaml | 7 +++ .../invalid/icons-withouth-name.yaml | 7 +++ .../invalid/missing-documentation.yaml | 7 +++ .../moduleconfig/invalid/missing-icons.yaml | 5 ++ .../invalid/missing-repository.yaml | 7 +++ .../invalid/non-https-documentation.yaml | 8 +++ .../invalid/non-https-repository.yaml | 8 +++ 10 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 tests/e2e/create/testdata/moduleconfig/invalid/non-https-documentation.yaml create mode 100644 tests/e2e/create/testdata/moduleconfig/invalid/non-https-repository.yaml diff --git a/tests/e2e/create/create_suite_test.go b/tests/e2e/create/create_suite_test.go index 2cca477..11ffab3 100644 --- a/tests/e2e/create/create_suite_test.go +++ b/tests/e2e/create/create_suite_test.go @@ -20,17 +20,22 @@ func Test_Create(t *testing.T) { const ( testdataDir = "./testdata/moduleconfig/" - invalidConfigs = testdataDir + "invalid/" - duplicateResources = invalidConfigs + "duplicate-resources.yaml" - missingNameConfig = invalidConfigs + "missing-name.yaml" - missingVersionConfig = invalidConfigs + "missing-version.yaml" - missingManifestConfig = invalidConfigs + "missing-manifest.yaml" - missingInfoConfig = invalidConfigs + "missing-info.yaml" - nonHttpsResource = invalidConfigs + "non-https-resource.yaml" - resourceWithoutLink = invalidConfigs + "resource-without-link.yaml" - resourceWithoutName = invalidConfigs + "resource-without-name.yaml" - manifestFileref = invalidConfigs + "manifest-fileref.yaml" - defaultCRFileref = invalidConfigs + "defaultcr-fileref.yaml" + invalidConfigs = testdataDir + "invalid/" + duplicateIcons = invalidConfigs + "duplicate-icons.yaml" + duplicateResources = invalidConfigs + "duplicate-resources.yaml" + missingNameConfig = invalidConfigs + "missing-name.yaml" + missingVersionConfig = invalidConfigs + "missing-version.yaml" + missingManifestConfig = invalidConfigs + "missing-manifest.yaml" + missingDocumentationConfig = invalidConfigs + "missing-documentation.yaml" + missingRepositoryConfig = invalidConfigs + "missing-repository.yaml" + missingIconsConfig = invalidConfigs + "missing-icons.yaml" + nonHttpsResource = invalidConfigs + "non-https-resource.yaml" + resourceWithoutLink = invalidConfigs + "resource-without-link.yaml" + resourceWithoutName = invalidConfigs + "resource-without-name.yaml" + iconsWithoutLink = invalidConfigs + "icons-without-link.yaml" + iconsWithoutName = invalidConfigs + "icons-without-name.yaml" + manifestFileref = invalidConfigs + "manifest-fileref.yaml" + defaultCRFileref = invalidConfigs + "defaultcr-fileref.yaml" validConfigs = testdataDir + "valid/" minimalConfig = validConfigs + "minimal.yaml" diff --git a/tests/e2e/create/create_test.go b/tests/e2e/create/create_test.go index 95fb99d..a162bc5 100644 --- a/tests/e2e/create/create_test.go +++ b/tests/e2e/create/create_test.go @@ -79,6 +79,62 @@ var _ = Describe("Test 'create' command", Ordered, func() { }) }) + Context("Given 'modulectl create' command", func() { + var cmd createCmd + It("When invoked with missing repository", func() { + cmd = createCmd{ + moduleConfigFile: missingRepositoryConfig, + } + }) + It("Then the command should fail", func() { + err := cmd.execute() + Expect(err).Should(HaveOccurred()) + Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate repository: invalid Option: must not be empty")) + }) + }) + + Context("Given 'modulectl create' command", func() { + var cmd createCmd + It("When invoked with missing documentation", func() { + cmd = createCmd{ + moduleConfigFile: missingDocumentationConfig, + } + }) + It("Then the command should fail", func() { + err := cmd.execute() + Expect(err).Should(HaveOccurred()) + Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate documentation: invalid Option: must not be empty")) + }) + }) + + Context("Given 'modulectl create' command", func() { + var cmd createCmd + It("When invoked with missing icons", func() { + cmd = createCmd{ + moduleConfigFile: missingIconsConfig, + } + }) + It("Then the command should fail", func() { + err := cmd.execute() + Expect(err).Should(HaveOccurred()) + Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate icons: invalid Option: must not be empty")) + }) + }) + + Context("Given 'modulectl create' command", func() { + var cmd createCmd + It("When invoked with duplicate entry in icons", func() { + cmd = createCmd{ + moduleConfigFile: duplicateIcons, + } + }) + It("Then the command should fail", func() { + err := cmd.execute() + Expect(err).Should(HaveOccurred()) + Expect(err.Error()).Should(ContainSubstring("failed to parse module config file: icons contain duplicate entries")) + }) + }) + Context("Given 'modulectl create' command", func() { var cmd createCmd It("When invoked with duplicate entry in resources", func() { diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/duplicate-icons.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/duplicate-icons.yaml index e69de29..10fb5da 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/duplicate-icons.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/duplicate-icons.yaml @@ -0,0 +1,13 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png +resources: + - name: someResource + link: https://some.other/location/template-operator.yaml diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/icons-without-link.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/icons-without-link.yaml index e69de29..ee91a02 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/icons-without-link.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/icons-without-link.yaml @@ -0,0 +1,7 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - name: module-icon diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/icons-withouth-name.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/icons-withouth-name.yaml index e69de29..7e708bf 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/icons-withouth-name.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/icons-withouth-name.yaml @@ -0,0 +1,7 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/missing-documentation.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/missing-documentation.yaml index e69de29..3f82b6a 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/missing-documentation.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/missing-documentation.yaml @@ -0,0 +1,7 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +icons: + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/missing-icons.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/missing-icons.yaml index e69de29..0df3255 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/missing-icons.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/missing-icons.yaml @@ -0,0 +1,5 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/missing-repository.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/missing-repository.yaml index e69de29..7d6ced2 100644 --- a/tests/e2e/create/testdata/moduleconfig/invalid/missing-repository.yaml +++ b/tests/e2e/create/testdata/moduleconfig/invalid/missing-repository.yaml @@ -0,0 +1,7 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/non-https-documentation.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/non-https-documentation.yaml new file mode 100644 index 0000000..fa6068d --- /dev/null +++ b/tests/e2e/create/testdata/moduleconfig/invalid/non-https-documentation.yaml @@ -0,0 +1,8 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: https://github.com/kyma-project/template-operator +documentation: http://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png diff --git a/tests/e2e/create/testdata/moduleconfig/invalid/non-https-repository.yaml b/tests/e2e/create/testdata/moduleconfig/invalid/non-https-repository.yaml new file mode 100644 index 0000000..c0083dc --- /dev/null +++ b/tests/e2e/create/testdata/moduleconfig/invalid/non-https-repository.yaml @@ -0,0 +1,8 @@ +name: kyma-project.io/module/template-operator +version: 1.0.0 +manifest: https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml +repository: http://github.com/kyma-project/template-operator +documentation: https://github.com/kyma-project/template-operator/blob/main/README.md +icons: + - name: module-icon + link: https://github.com/kyma-project/template-operator/blob/main/docs/assets/logo.png