Skip to content

Commit

Permalink
test(e2e): test tip of the branch (#40)
Browse files Browse the repository at this point in the history
Instead of running tests against the extension installed from the latest release (by installing tarball from GitHub Releases via dfx extension install), we will run tests against extensions built from the source code of the tip of the branch.
  • Loading branch information
Marcin Nowak-Liebiediew authored Aug 4, 2023
1 parent 6df55b9 commit 0a5059a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
if: contains(matrix.os, 'macos-12') == false
- name: Install sponge and timeout
run: brew install coreutils sponge
- name: Install cargo-dist
run: cargo install cargo-dist
- name: Install IC SDK (dfx)
run: sh -ci "$(curl -sSL https://internetcomputer.org/install.sh)"
- name: run test
Expand Down
34 changes: 32 additions & 2 deletions e2e/utils.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
set -e

GIT_ROOT_DIR=$(git rev-parse --show-toplevel)

export CARGO_HOME="$HOME"
load "$GIT_ROOT_DIR"/e2e/bats-support/load
load "$GIT_ROOT_DIR"/e2e/bats-assert/load

Expand All @@ -22,6 +21,19 @@ install_shared_asset() {
cp -R "$ASSET_ROOT"/* "$(dirname "$E2E_NETWORKS_JSON")"
}

dfx_extension_install_manually() (
cd "$GIT_ROOT_DIR"
local extension_name="$1"
package_version=$(HOME="$CARGO_HOME" cargo metadata --format-version=1 | jq -r '.workspace_members[]' | grep "$extension_name" | cut -d" " -f2)
HOME="$CARGO_HOME" cargo dist build --tag="$extension_name-v$package_version" # cargo-dist needs git tag only metadata-related stuff; it won't do git checkout, it will build from HEAD
extensions_dir="$(dfx cache show)/extensions"
arch_platform="$(get_arch_and_platform)"
rm -rf "$extensions_dir/$extension_name-$arch_platform" "${extensions_dir:?}/$extension_name" # remove old versions
mkdir -p "$extensions_dir"
tar xfJ "target/distrib/$extension_name-$arch_platform.tar.xz" -C "$extensions_dir"
mv "$extensions_dir/$extension_name-$arch_platform" "$extensions_dir/$extension_name"
)

standard_setup() {
# We want to work from a temporary directory, different for every test.
x=$(mktemp -d -t dfx-e2e-XXXXXXXX)
Expand Down Expand Up @@ -446,3 +458,21 @@ assert_no_dfx_start_or_replica_processes() {
fi
}

get_arch_and_platform() {
ARCH=$(uname -m)
SYS=$(uname -s)

if [[ "$ARCH" == "x86_64" ]]; then
if [[ "$SYS" == "Darwin" ]]; then
echo "$ARCH-apple-darwin"
elif [[ "$SYS" == "Linux" ]]; then
echo "$ARCH-unknown-linux-gnu"
else
echo "System not recognized"
fi
elif [[ "$ARCH" == "arm64" && "$SYS" == "Darwin" ]]; then
echo "aarch64-apple-darwin"
else
echo "Architecture not recognized"
fi
}
5 changes: 2 additions & 3 deletions extensions/nns/e2e/tests/nns.bash
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env bats

GIT_ROOT_DIR=$(git rev-parse --show-toplevel)

export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)"
load "$GIT_ROOT_DIR"/e2e/utils.sh

assets="$(dirname "$BATS_TEST_FILENAME")"/../assets

setup() {
standard_setup

dfx extension install nns
dfx_extension_install_manually nns

dfx_new
}
Expand Down
8 changes: 4 additions & 4 deletions extensions/sns/e2e/tests/sns.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bats

GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)"

load "$GIT_ROOT_DIR"/e2e/utils.sh

setup() {
standard_setup

dfx extension install sns
dfx_extension_install_manually sns
}

teardown() {
Expand Down Expand Up @@ -60,8 +60,8 @@ SNS_CONFIG_FILE_NAME="sns.yml"
}

@test "sns deploy fails without config file" {
dfx_extension_install_manually nns
dfx_new
dfx extension install nns
dfx nns import
rm -f sns.yml # Is not expected to be present anyway
run dfx sns deploy
Expand All @@ -70,11 +70,11 @@ SNS_CONFIG_FILE_NAME="sns.yml"
}

@test "sns deploy succeeds" {
dfx_extension_install_manually nns
dfx_new
install_shared_asset subnet_type/shared_network_settings/system
dfx start --clean --background --host 127.0.0.1:8080
sleep 1
dfx extension install nns
dfx nns install
dfx nns import
dfx sns import
Expand Down

0 comments on commit 0a5059a

Please sign in to comment.