From a2275f58f4aee1962f68635b31d30aeed3bea367 Mon Sep 17 00:00:00 2001 From: Joseph Kim Date: Wed, 9 Mar 2022 10:20:33 -0500 Subject: [PATCH 1/3] Revert workaround as odo install issue is fixed Signed-off-by: Joseph Kim --- .github/workflows/pytest.yaml | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index d1cda8a..42b7e9a 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -33,31 +33,11 @@ jobs: - name: Start minikube uses: medyagh/setup-minikube@latest -# This step is disabled until the issue is addressed: https://github.com/redhat-actions/openshift-tools-installer/issues/66 -# - name: Install ODO -# uses: redhat-actions/openshift-tools-installer@v1 -# with: -# # Installs the latest release of odo -# odo: "latest" - - - name: Install ODO for Linux - if: matrix.os == 'ubuntu-latest' - run: | - curl -L https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/odo/latest/odo-linux-amd64 -o odo - curl -L https://developers.redhat.com/content-gateway/rest/mirror/pub/openshift-v4/clients/odo/latest/odo-linux-amd64.sha256 -o odo.sha256 - echo "$( Date: Wed, 13 Apr 2022 15:44:51 -0400 Subject: [PATCH 2/3] Add integration tests with Odo 3.0 Signed-off-by: Joseph Kim --- .github/workflows/pytest.yaml | 4 +- .github/workflows/pytest_odo.300.yaml | 69 ++++++++ .../devfile-with-starter-with-devfile.yaml | 52 ++++++ .../devfiles/nodejs/devfile-with-tag.yaml | 50 ++++++ .../springboot/devfile-with-subDir.yaml | 51 ++++++ tests/odo/__init__.py | 3 + tests/{ => odo}/test_build_images_cmd.py | 4 +- tests/{ => odo}/test_catalog_cmd.py | 0 tests/{ => odo}/test_config_cmd.py | 4 +- tests/{ => odo}/test_create_cmd.py | 6 +- tests/{ => odo}/test_deploy_cmd.py | 6 +- tests/{ => odo}/test_describe_cmd.py | 4 +- tests/{ => odo}/test_dot_devfile_cmd.py | 2 +- tests/{ => odo}/test_list_cmd.py | 6 +- tests/{ => odo}/test_push_cmd.py | 12 +- tests/{ => odo}/test_url_cmd.py | 8 +- tests/odo_300/__init__.py | 3 + tests/odo_300/test_init_cmd.py | 152 ++++++++++++++++++ tests/utils/config.py | 33 +++- tests/utils/util.py | 21 +++ 20 files changed, 457 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/pytest_odo.300.yaml create mode 100644 tests/examples/source/devfiles/nodejs/devfile-with-starter-with-devfile.yaml create mode 100644 tests/examples/source/devfiles/nodejs/devfile-with-tag.yaml create mode 100644 tests/examples/source/devfiles/springboot/devfile-with-subDir.yaml create mode 100644 tests/odo/__init__.py rename tests/{ => odo}/test_build_images_cmd.py (91%) rename tests/{ => odo}/test_catalog_cmd.py (100%) rename tests/{ => odo}/test_config_cmd.py (93%) rename tests/{ => odo}/test_create_cmd.py (96%) rename tests/{ => odo}/test_deploy_cmd.py (93%) rename tests/{ => odo}/test_describe_cmd.py (95%) rename tests/{ => odo}/test_dot_devfile_cmd.py (96%) rename tests/{ => odo}/test_list_cmd.py (91%) rename tests/{ => odo}/test_push_cmd.py (94%) rename tests/{ => odo}/test_url_cmd.py (94%) create mode 100644 tests/odo_300/__init__.py create mode 100644 tests/odo_300/test_init_cmd.py diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 5a6df6e..ecbe2ad 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -5,7 +5,7 @@ # # SPDX-License-Identifier: EPL-2.0 # -name: Devfile integration tests +name: Devfile integration tests (latest Odo release) on: push: @@ -48,5 +48,5 @@ jobs: - name: Run test with pipenv and pytest run: | odo version - pipenv run pytest tests -v + pipenv run pytest tests/odo -v diff --git a/.github/workflows/pytest_odo.300.yaml b/.github/workflows/pytest_odo.300.yaml new file mode 100644 index 0000000..4771a23 --- /dev/null +++ b/.github/workflows/pytest_odo.300.yaml @@ -0,0 +1,69 @@ +# Copyright (c) 2021 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +name: Devfile integration tests (latest Odo build) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + # every day at 9am EST + - cron: 0 1 * * * + +jobs: + test_with_minikube: + name: Run tests + strategy: + matrix: + os: [ ubuntu-latest, macos-10.15 ] + runs-on: ${{ matrix.os }} + continue-on-error: true + timeout-minutes: 20 + + steps: + - name: Check out repository code + uses: actions/checkout@v2 + + - name: Check out the latest odo repository code + uses: actions/checkout@v2 + with: + repository: redhat-developer/odo + ref: main + path: odo + + - name: Start minikube + uses: medyagh/setup-minikube@latest + + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '1.16.1' + - run: go version + + # Build and installs odo from source code + - name: Build and Install ODO + run: | + cd odo + make goget-tools + make bin + mv ./odo /usr/local/bin/odo + cd .. + rm -rf odo + + # Setup Python + - name: Install Python, pipenv and Pipfile packages + uses: palewire/install-python-pipenv-pipfile@v2 + with: + python-version: "3.9.10" + + - name: Run test with pipenv and pytest + run: | + odo version + pipenv run pytest tests/odo_300 -v + diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-starter-with-devfile.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-starter-with-devfile.yaml new file mode 100644 index 0000000..89207ff --- /dev/null +++ b/tests/examples/source/devfiles/nodejs/devfile-with-starter-with-devfile.yaml @@ -0,0 +1,52 @@ +schemaVersion: 2.0.0 +metadata: + name: nodejs + projectType: nodejs + language: nodejs +starterProjects: + - name: nodejs-starter + git: + remotes: + origin: "https://github.com/nodeshift-starters/devfile-sample.git" + checkoutFrom: + revision: main +components: + - name: runtime + container: + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 + memoryLimit: 1024Mi + endpoints: + - name: "3000-tcp" + targetPort: 3000 + mountSources: true +commands: + - id: devbuild + exec: + component: runtime + commandLine: npm install + workingDir: ${PROJECTS_ROOT} + group: + kind: build + isDefault: true + - id: build + exec: + component: runtime + commandLine: npm install + workingDir: ${PROJECTS_ROOT} + group: + kind: build + - id: devrun + exec: + component: runtime + commandLine: npm start + workingDir: ${PROJECTS_ROOT} + group: + kind: run + isDefault: true + - id: run + exec: + component: runtime + commandLine: npm start + workingDir: ${PROJECTS_ROOT} + group: + kind: run diff --git a/tests/examples/source/devfiles/nodejs/devfile-with-tag.yaml b/tests/examples/source/devfiles/nodejs/devfile-with-tag.yaml new file mode 100644 index 0000000..b2ed079 --- /dev/null +++ b/tests/examples/source/devfiles/nodejs/devfile-with-tag.yaml @@ -0,0 +1,50 @@ +schemaVersion: 2.0.0 +metadata: + name: nodejs +starterProjects: + - name: nodejs-starter + git: + remotes: + origin: "https://github.com/odo-devfiles/nodejs-ex.git" + checkoutFrom: + revision: 0.0.1 +components: + - name: runtime + container: + image: registry.access.redhat.com/ubi8/nodejs-12:1-36 + memoryLimit: 1024Mi + endpoints: + - name: "3000-tcp" + targetPort: 3000 + mountSources: true +commands: + - id: devbuild + exec: + component: runtime + commandLine: npm install + workingDir: ${PROJECTS_ROOT} + group: + kind: build + isDefault: true + - id: build + exec: + component: runtime + commandLine: npm install + workingDir: ${PROJECTS_ROOT} + group: + kind: build + - id: devrun + exec: + component: runtime + commandLine: npm start + workingDir: ${PROJECTS_ROOT} + group: + kind: run + isDefault: true + - id: run + exec: + component: runtime + commandLine: npm start + workingDir: ${PROJECTS_ROOT} + group: + kind: run diff --git a/tests/examples/source/devfiles/springboot/devfile-with-subDir.yaml b/tests/examples/source/devfiles/springboot/devfile-with-subDir.yaml new file mode 100644 index 0000000..49d47f5 --- /dev/null +++ b/tests/examples/source/devfiles/springboot/devfile-with-subDir.yaml @@ -0,0 +1,51 @@ +--- +schemaVersion: 2.0.0 +metadata: + name: java-springboot +starterProjects: + - name: springbootproject + subDir: "/src/main" + git: + remotes: + origin: "https://github.com/odo-devfiles/springboot-ex.git" +components: + - name: tools + container: + image: quay.io/eclipse/che-java11-maven:next + memoryLimit: 768Mi + command: ['tail'] + args: [ '-f', '/dev/null'] + mountSources: true + volumeMounts: + - name: springbootpvc + path: /data/cache/.m2 + - name: runtime + container: + image: quay.io/eclipse/che-java11-maven:next + memoryLimit: 768Mi + endpoints: + - name: "8080-tcp" + targetPort: 8080 + volumeMounts: + - name: springbootpvc + path: /data/cache/.m2 + mountSources: true + - name: springbootpvc + volume: + size: 3Gi +commands: + - id: defaultbuild + exec: + component: tools + commandLine: "mvn clean -Dmaven.repo.local=/data/cache/.m2/repository package -Dmaven.test.skip=true" + workingDir: /projects + group: + kind: build + - id: defaultrun + exec: + component: runtime + commandLine: "mvn -Dmaven.repo.local=/data/cache/.m2/repository spring-boot:run" + workingDir: /projects + group: + kind: run + isDefault: true \ No newline at end of file diff --git a/tests/odo/__init__.py b/tests/odo/__init__.py new file mode 100644 index 0000000..8eff392 --- /dev/null +++ b/tests/odo/__init__.py @@ -0,0 +1,3 @@ +import os +import sys +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) \ No newline at end of file diff --git a/tests/test_build_images_cmd.py b/tests/odo/test_build_images_cmd.py similarity index 91% rename from tests/test_build_images_cmd.py rename to tests/odo/test_build_images_cmd.py index 885ca49..3b8e947 100644 --- a/tests/test_build_images_cmd.py +++ b/tests/odo/test_build_images_cmd.py @@ -29,7 +29,7 @@ def test_build_push_images(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-outerloop.yaml') + '../examples/source/devfiles/nodejs/devfile-outerloop.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -55,7 +55,7 @@ def test_build_images_with_dockerfile_args(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-outerloop-args.yaml') + '../examples/source/devfiles/nodejs/devfile-outerloop-args.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) diff --git a/tests/test_catalog_cmd.py b/tests/odo/test_catalog_cmd.py similarity index 100% rename from tests/test_catalog_cmd.py rename to tests/odo/test_catalog_cmd.py diff --git a/tests/test_config_cmd.py b/tests/odo/test_config_cmd.py similarity index 93% rename from tests/test_config_cmd.py rename to tests/odo/test_config_cmd.py index f6afe62..4cf3542 100644 --- a/tests/test_config_cmd.py +++ b/tests/odo/test_config_cmd.py @@ -29,7 +29,7 @@ def test_config_view(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-registry.yaml') + '../examples/source/devfiles/nodejs/devfile-registry.yaml') shutil.copyfile(source_devfile_path, devfile_path) subprocess.check_call(["odo", "create", "nodejs", "--devfile", "./devfile.yaml"]) @@ -63,7 +63,7 @@ def test_config_set(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-registry.yaml') + '../examples/source/devfiles/nodejs/devfile-registry.yaml') shutil.copyfile(source_devfile_path, devfile_path) subprocess.check_call(["odo", "create", "nodejs", "--devfile", "./devfile.yaml"]) diff --git a/tests/test_create_cmd.py b/tests/odo/test_create_cmd.py similarity index 96% rename from tests/test_create_cmd.py rename to tests/odo/test_create_cmd.py index 707cdcd..58a5707 100644 --- a/tests/test_create_cmd.py +++ b/tests/odo/test_create_cmd.py @@ -94,7 +94,7 @@ def test_create_component_from_devfile_starter_project(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/java-openliberty/devfile.yaml') + '../examples/source/devfiles/java-openliberty/devfile.yaml') source_devfile_path = os.path.abspath(source_devfile_path) @@ -132,7 +132,7 @@ def test_create_component_with_starter_project_git_branch(self): os.chdir(tmp_workspace) source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-with-branch.yaml') + '../examples/source/devfiles/nodejs/devfile-with-branch.yaml') copy_example_devfile(source_devfile_path, tmp_workspace) subprocess.run(["odo", "create", "nodejs", "--starter", "nodejs-starter"]) @@ -153,7 +153,7 @@ def test_create_component_with_devfile_flag(self): os.chdir(tmp_workspace) source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_example_devfile(source_devfile_path, tmp_workspace) subprocess.run(["odo", "create", "nodejs", "--devfile", "./devfile.yaml"]) diff --git a/tests/test_deploy_cmd.py b/tests/odo/test_deploy_cmd.py similarity index 93% rename from tests/test_deploy_cmd.py rename to tests/odo/test_deploy_cmd.py index 2cb9e7d..8c4430f 100644 --- a/tests/test_deploy_cmd.py +++ b/tests/odo/test_deploy_cmd.py @@ -30,7 +30,7 @@ def test_deploy(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-deploy.yaml') + '../examples/source/devfiles/nodejs/devfile-deploy.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -62,7 +62,7 @@ def test_deploy_image_component(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-outerloop-project_source-in-docker-build-context.yaml') + '../examples/source/devfiles/nodejs/devfile-outerloop-project_source-in-docker-build-context.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -100,7 +100,7 @@ def test_deploy_image_component(self): # # # example devfile path # source_devfile_path = os.path.join(os.path.dirname(__file__), - # 'examples/source/devfiles/nodejs/devfile-with-two-deploy-commands.yaml') + # '../examples/source/devfiles/nodejs/devfile-with-two-deploy-commands.yaml') # # copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) # diff --git a/tests/test_describe_cmd.py b/tests/odo/test_describe_cmd.py similarity index 95% rename from tests/test_describe_cmd.py rename to tests/odo/test_describe_cmd.py index ee2af74..31e8e49 100644 --- a/tests/test_describe_cmd.py +++ b/tests/odo/test_describe_cmd.py @@ -124,7 +124,7 @@ def test_describe_missing_metadata(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/springboot/devfile-with-missing-projectType-metadata.yaml') + '../examples/source/devfiles/springboot/devfile-with-missing-projectType-metadata.yaml') copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT) @@ -145,7 +145,7 @@ def test_describe_missing_metadata_and_language(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/springboot/devfile-with-missing-projectType-and-language-metadata.yaml') + '../examples/source/devfiles/springboot/devfile-with-missing-projectType-and-language-metadata.yaml') copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT) diff --git a/tests/test_dot_devfile_cmd.py b/tests/odo/test_dot_devfile_cmd.py similarity index 96% rename from tests/test_dot_devfile_cmd.py rename to tests/odo/test_dot_devfile_cmd.py index faee9ba..4349777 100644 --- a/tests/test_dot_devfile_cmd.py +++ b/tests/odo/test_dot_devfile_cmd.py @@ -33,7 +33,7 @@ def test_url_create_with_dot_devfile(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) diff --git a/tests/test_list_cmd.py b/tests/odo/test_list_cmd.py similarity index 91% rename from tests/test_list_cmd.py rename to tests/odo/test_list_cmd.py index d4e8c9c..d3a509f 100644 --- a/tests/test_list_cmd.py +++ b/tests/odo/test_list_cmd.py @@ -32,7 +32,7 @@ def test_list_component_in_application(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -74,7 +74,7 @@ def test_list_component_missing_metadata_projecttype(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/springboot/devfile-with-missing-projectType-metadata.yaml') + '../examples/source/devfiles/springboot/devfile-with-missing-projectType-metadata.yaml') copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT) @@ -109,7 +109,7 @@ def test_list_component_missing_metadata_projecttype_language(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/springboot/devfile-with-missing-projectType-and-language-metadata.yaml') + '../examples/source/devfiles/springboot/devfile-with-missing-projectType-and-language-metadata.yaml') copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT) diff --git a/tests/test_push_cmd.py b/tests/odo/test_push_cmd.py similarity index 94% rename from tests/test_push_cmd.py rename to tests/odo/test_push_cmd.py index a04e069..99fe272 100644 --- a/tests/test_push_cmd.py +++ b/tests/odo/test_push_cmd.py @@ -31,7 +31,7 @@ def test_push_with_devfile(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-registry.yaml') + '../examples/source/devfiles/nodejs/devfile-registry.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -62,7 +62,7 @@ def test_push_with_json_output(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -88,7 +88,7 @@ def test_push_with_env_variable(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-variables.yaml') + '../examples/source/devfiles/nodejs/devfile-variables.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -119,7 +119,7 @@ def test_push_with_sourcemappings(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfileSourceMapping.yaml') + '../examples/source/devfiles/nodejs/devfileSourceMapping.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -164,7 +164,7 @@ def test_push_with_clonepath(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-with-projects.yaml') + '../examples/source/devfiles/nodejs/devfile-with-projects.yaml') copy_example_devfile(source_devfile_path, tmp_workspace) result = subprocess.run(["odo", "push", "--v", "5"], @@ -210,7 +210,7 @@ def test_push_with_project(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile-with-projects.yaml') + '../examples/source/devfiles/nodejs/devfile-with-projects.yaml') copy_example_devfile(source_devfile_path, tmp_workspace) replace_string_in_a_file("devfile.yaml", "clonePath: webapp/", "# clonePath: webapp/") result = subprocess.run(["odo", "push"], diff --git a/tests/test_url_cmd.py b/tests/odo/test_url_cmd.py similarity index 94% rename from tests/test_url_cmd.py rename to tests/odo/test_url_cmd.py index 0b7d8ad..7d8027e 100644 --- a/tests/test_url_cmd.py +++ b/tests/odo/test_url_cmd.py @@ -39,7 +39,7 @@ def test_url_duplicate_name_port(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -69,7 +69,7 @@ def test_url_invalid_container(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -91,7 +91,7 @@ def test_url_create_and_delete(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) @@ -130,7 +130,7 @@ def test_url_create_multiple_endpoints(self): # example devfile path source_devfile_path = os.path.join(os.path.dirname(__file__), - 'examples/source/devfiles/nodejs/devfile.yaml') + '../examples/source/devfiles/nodejs/devfile.yaml') copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT) diff --git a/tests/odo_300/__init__.py b/tests/odo_300/__init__.py new file mode 100644 index 0000000..8abafde --- /dev/null +++ b/tests/odo_300/__init__.py @@ -0,0 +1,3 @@ +import os +import sys +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) diff --git a/tests/odo_300/test_init_cmd.py b/tests/odo_300/test_init_cmd.py new file mode 100644 index 0000000..7f89c2e --- /dev/null +++ b/tests/odo_300/test_init_cmd.py @@ -0,0 +1,152 @@ +import sys +import tempfile +from utils.config import * +from utils.util import * + +@pytest.mark.usefixtures("use_test_registry_v300") +class TestInitCmd: + + CONTEXT = "test-context" + + tmp_project_name = None + + @classmethod + def setup_class(cls): + # Runs once per class + cls.tmp_project_name = create_test_project() + + @classmethod + def teardown_class(cls): + '''Runs at end of class''' + subprocess.run(["odo", "project", "delete", cls.tmp_project_name, "-f", "-w"]) + + def test_init_with_devfile_flag(self): + + print("Test case : should download a devfile.yaml file and correctly set the component name in it") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + compName = "acomponent" + result = subprocess.run(["odo", "init", "--name", compName, "--devfile", "go"], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + assert check_file_exist(tmp_workspace, "devfile.yaml") + + devfile_path = os.path.abspath(os.path.join(tmp_workspace, 'devfile.yaml')) + assert query_yaml(devfile_path, "metadata", "name", -1) == compName + + + def test_init_with_starter(self): + + print("Test case : should pass and keep the devfile in starter") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + + source_devfile_path = os.path.join(os.path.dirname(__file__), + '../examples/source/devfiles/nodejs/devfile-with-starter-with-devfile.yaml') + + compName = "acomponent" + result = subprocess.run(["odo", "init", "--name", compName, "--starter", "nodejs-starter", "--devfile-path", source_devfile_path], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + assert check_file_exist(tmp_workspace, "devfile.yaml") + + devfile_path = os.path.abspath(os.path.join(tmp_workspace, 'devfile.yaml')) + assert query_yaml(devfile_path, "metadata", "name", -1) == compName + assert query_yaml(devfile_path, "metadata", "language", -1) == "nodejs" + + list_contents: list[str] = [ + "2.2.0", "outerloop-deploy", "deployk8s", "outerloop-build" + ] + assert match_strings_in_file(devfile_path, list_contents) + + + def test_init_with_starter_subdir(self): + + print("Test case : should successfully extract the project in the specified subDir path") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + + source_devfile_path = os.path.join(os.path.dirname(__file__), + '../examples/source/devfiles/springboot/devfile-with-subDir.yaml') + compName = "acomponent" + result = subprocess.run(["odo", "init", "--name", compName, "--starter", "springbootproject", "--devfile-path", source_devfile_path], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + + list_files: list[str] = [ + "java/com/example/demo/DemoApplication.java", + "resources/application.properties" + ] + assert check_files_exist(tmp_workspace, list_files) + + + def test_init_with_starter_and_branch(self): + + print("Test case : should successfully run odo init for devfile with starter project from the specified branch") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + + source_devfile_path = os.path.join(os.path.dirname(__file__), + '../examples/source/devfiles/nodejs/devfile-with-branch.yaml') + compName = "acomponent" + result = subprocess.run(["odo", "init", "--name", compName, "--starter", "nodejs-starter", "--devfile-path", source_devfile_path], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + + list_files: list[str] = [ + "package.json", "package-lock.json", "README.md", "devfile.yaml", "test" + ] + assert check_files_exist(tmp_workspace, list_files) + + + def test_init_with_starter_and_tag(self): + + print("Test case : should successfully run odo init for devfile with starter project from the specified tag") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + + source_devfile_path = os.path.join(os.path.dirname(__file__), + '../examples/source/devfiles/nodejs/devfile-with-tag.yaml') + compName = "acomponent" + result = subprocess.run(["odo", "init", "--name", compName, "--starter", "nodejs-starter", "--devfile-path", source_devfile_path], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + + list_files: list[str] = [ + "package.json", "package-lock.json", "README.md", "devfile.yaml", "app" + ] + assert check_files_exist(tmp_workspace, list_files) + + + def test_init_with_sources(self): + + print("Test case : running odo init from a directory with sources") + + with tempfile.TemporaryDirectory() as tmp_workspace: + os.chdir(tmp_workspace) + copy_example("nodejs/project", tmp_workspace, self.CONTEXT) + os.chdir(self.CONTEXT) + + compName = "acomponent" + + # should work without --starter flag + result = subprocess.run(["odo", "init", "--name", compName, "--devfile", "nodejs"], + capture_output=True, text=True, check=True) + + assert contains(result.stdout, "Your new component '{}' is ready in the current directory.".format(compName)) + + # should not accept --starter flag + result = subprocess.run(["odo", "init", "--name", compName, "--devfile", "nodejs", "--starter", "nodejs-starter"], + capture_output=True, text=True, check=False) + + assert contains(result.stderr, "a devfile already exists in the current directory") diff --git a/tests/utils/config.py b/tests/utils/config.py index 914d7b5..da64db2 100644 --- a/tests/utils/config.py +++ b/tests/utils/config.py @@ -13,27 +13,50 @@ def use_test_registry(): test_registry_url = "https://registry.stage.devfile.io" print('Check if ', test_registry_name, 'exists and update URL if needed.') + result = subprocess.run(["odo", "registry", "list"], capture_output=True, text=True, check=True) if contains(result.stdout, test_registry_name): print('Updating', test_registry_name, '...') + subprocess.run(["odo", "registry", "update", test_registry_name, test_registry_url, '-f'], capture_output=True, text=True, check=True) else: print('Creating', test_registry_name, '...') subprocess.run(["odo", "registry", "add", test_registry_name, test_registry_url], capture_output=True, text=True, check=True) + print('Using', test_registry_name, ':', test_registry_url) + + yield test_registry_name + + +@pytest.fixture(scope="session") +def use_test_registry_v300(): + + # Use staging OCI-based registry for tests to avoid overload + test_registry_name = "TestDevfileRegistry" + test_registry_url = "https://registry.stage.devfile.io" + + print('Check if', test_registry_name, 'exists and update URL if needed.') + + result = subprocess.run(["odo", "preference", "registry", "list"], + capture_output=True, text=True, check=True) + + if contains(result.stdout, test_registry_name): + print('Updating', test_registry_name, '...') + + subprocess.run(["odo", "preference", "registry", "update", test_registry_name, test_registry_url, '-f'], + capture_output=True, text=True, check=True) + else: + print('Creating', test_registry_name, '...') + subprocess.run(["odo", "preference", "registry", "add", test_registry_name, test_registry_url], + capture_output=True, text=True, check=True) print('Using', test_registry_name, ':', test_registry_url) yield test_registry_name - # Todo: this causes an intermittent failure - # result = subprocess.run(["odo", "registry", "delete", test_registry_name, "-f"], - # capture_output=True, text=True, check=True) - # - # print('Removed test registry:', test_registry_name) def create_test_project(): diff --git a/tests/utils/util.py b/tests/utils/util.py index 9d2c6a5..9ba95a0 100644 --- a/tests/utils/util.py +++ b/tests/utils/util.py @@ -31,6 +31,23 @@ def unmatch_all(input, list_not_expected): return False return True +# check if multiple strings in list_expected are found in a file +def match_strings_in_file(file_name, list_expected): + for search_string in list_expected: + if not match_string_in_file(file_name, search_string): + return False + + return True + +# check if a single search_string is found in a file +def match_string_in_file(file_name, search_string): + with open(file_name, 'r') as read_file: + for line in read_file: + if contains(line, search_string): + return True + + return False + # This function loads the given devfile def get_devfile(devfile_path = 'devfile.yaml'): with open(devfile_path, 'r') as file: @@ -101,6 +118,10 @@ def check_files_exist(context, list_files): return False return True +# check if file exist in the context +def check_file_exist(context, a_file): + return os.path.exists(os.path.join(context, a_file)) + # wait until the file exists # def wait_for_file(source_dir, filename, timeout = 20): # From 1bf22f317fe3c685c338aee2c5ef050088add5c8 Mon Sep 17 00:00:00 2001 From: Joseph Kim Date: Wed, 13 Apr 2022 17:07:19 -0400 Subject: [PATCH 3/3] Update util Signed-off-by: Joseph Kim --- tests/utils/util.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/utils/util.py b/tests/utils/util.py index 9ba95a0..2464e2a 100644 --- a/tests/utils/util.py +++ b/tests/utils/util.py @@ -48,11 +48,11 @@ def match_string_in_file(file_name, search_string): return False -# This function loads the given devfile -def get_devfile(devfile_path = 'devfile.yaml'): - with open(devfile_path, 'r') as file: - devfile_data = yaml.safe_load(file) - return devfile_data +# This function loads the given yaml +def get_yaml(yaml_file_path): + with open(yaml_file_path, 'r') as file: + yaml_data = yaml.safe_load(file) + return yaml_data # This function loads the given schema available def get_schema_json(): @@ -62,7 +62,7 @@ def get_schema_json(): def validate_json(): execute_api_schema = get_schema_json() - json_data = get_devfile() + json_data = get_yaml() try: validate(instance=json_data, schema=execute_api_schema) @@ -94,17 +94,17 @@ def set_default_devfile_registry(): def random_string(size=8, chars=string.ascii_lowercase + string.digits): return ''.join(random.choice(chars) for _ in range(size)) -def query_yaml(devfile_path: str, param_1, param_2, param_3): +def query_yaml(yaml_path: str, param_1, param_2, param_3): try: - devfile_data = get_devfile(devfile_path) - print('devfile_data content:', devfile_data) + yaml_data = get_yaml(yaml_path) + print('yaml_data content:', yaml_data) if param_2 == -1: - return devfile_data[param_1] + return yaml_data[param_1] elif param_3 == -1: - return devfile_data[param_1][param_2] + return yaml_data[param_1][param_2] else: - return devfile_data[param_1][param_2][param_3] + return yaml_data[param_1][param_2][param_3] except yaml.YAMLError as e: print(e)