Skip to content

Commit

Permalink
Test integration test in ci
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Meister <[email protected]>
  • Loading branch information
dennismeister93 committed Aug 28, 2023
1 parent d290e23 commit 9d028c9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ jobs:
repository: eclipse-velocitas/vehicle-app-${{ matrix.language }}-template
path: test/${{ matrix.language }}/repo

- name: Install requirements
run: pip install -r test/requirements.txt

- name: Test for Auto-Upgrade
run: |
cd test/${{ matrix.language }}/repo
pytest -s ../../integration/test_poststart.py
- name: Prepare .velocitas.json for integration test
run: |
COMMIT_REF=$GITHUB_SHA
Expand Down
14 changes: 10 additions & 4 deletions setup/src/common/scripts/postStartCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#
# SPDX-License-Identifier: Apache-2.0

set -e

echo "#######################################################"
echo "### Auto-Upgrade CLI ###"
echo "#######################################################"
Expand All @@ -33,11 +31,19 @@ else
CLI_RELEASES_URL=https://api.github.com/repos/eclipse-velocitas/cli/releases/tags/${DESIRED_VERSION}
fi

DESIRED_VERSION_TAG=$(curl -s -L \
CLI_RELEASES=$(curl -s -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${AUTHORIZATION_HEADER} \
${CLI_RELEASES_URL} | jq -r .name)
${CLI_RELEASES_URL})

res=$?
if test "$res" != "0"; then
echo "the curl command failed with exit code: $res"
exit 0
fi

DESIRED_VERSION_TAG=$(echo ${CLI_RELEASES} | jq -r .name)

if [ "$DESIRED_VERSION_TAG" = "null" ] || [ "$DESIRED_VERSION_TAG" = "" ]; then
echo "> Can't find desired Velocitas CLI version: $DESIRED_VERSION. Skipping Auto-Upgrade."
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/.velocitas.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"appExecutionPlatforms": "linux/amd64",
"generatedModelPath": "./app/vehicle_model"
},
"cliVersion": "latest"
"cliVersion": "v0.5.5"
}
71 changes: 71 additions & 0 deletions test/integration/test_poststart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2023 Robert Bosch GmbH
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0

import json
import os
import platform
from re import Pattern, compile, search
from subprocess import PIPE, Popen, check_output


def get_cli_asset_name() -> str:
arch = platform.machine()
if arch == "amd64":
arch = "x64"
if arch == "aarch64":
arch = "arm64"
return f"velocitas-linux-{arch}"


def download_older_cli_version():
cli_asset_name = get_cli_asset_name()
cli_install_path = "/usr/bin/velocitas"
cli_download_url = f"https://github.com/eclipse-velocitas/cli/releases/download/v0.5.4/{cli_asset_name}" # noqa: E501

print(
f"Downloading CLI version v0.5.4 from {cli_download_url} to {cli_install_path}"
)
download_cli = f"sudo curl -s -L {cli_download_url} -o {cli_install_path}"
chmod = f"sudo chmod +x {cli_install_path}"

cli_download_process = Popen(download_cli, stdout=PIPE, shell=True)
cli_download_process.wait()
Popen(chmod, stdout=PIPE, shell=True)


def test_post_start_auto_upgrade_cli():
download_older_cli_version()

post_create_script_path = os.path.join(
os.getcwd(), "..", "..", "..", "setup", "src", "common", "scripts", "postStartCommand.sh"
)
print(post_create_script_path)
print(post_create_script_path)
post_create_script_process = Popen(
f"{post_create_script_path}", stdout=PIPE, shell=True
)
post_create_script_process.wait()

velocitas_version_output = check_output(["velocitas", "--version"]).decode()
search_velocitas_version_regex: Pattern[str] = compile(
r"velocitas-cli\/(\w+.\w+.\w+).*"
)
updated_cli_version = search(
search_velocitas_version_regex, velocitas_version_output
).group(1)

velocitas_json = open(os.path.join(os.getcwd(), ".velocitas.json"))
data = json.load(velocitas_json)
print(data)
assert data["cliVersion"] == f"v{updated_cli_version}"
2 changes: 1 addition & 1 deletion test/python/.velocitas.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"githubRepoId": "eclipse-velocitas/vehicle-app-python-template",
"generatedModelPath": "./gen/vehicle_model"
},
"cliVersion": "latest"
"cliVersion": "v0.5.5"
}
7 changes: 7 additions & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pytest==7.2.1
pytest-ordering==0.6
pytest-asyncio==0.20.3
pytest-cov==4.0.0
types-mock
coverage2clover==3.3.0
coveragepy-lcov==0.1.2

0 comments on commit 9d028c9

Please sign in to comment.