Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple integration tests for the x86_64 binary, and, the ext4 & xfs filesystems #11

Merged
merged 6 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Build 🔨 and Release 🚀

on:
Expand Down Expand Up @@ -26,35 +27,78 @@ jobs:
platforms: ${{ matrix.architecture }}
- name: Build and Test 🔨
run: ./build/docker.sh --architecture ${{ matrix.architecture }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
if-no-files-found: error
retention-days: 1

integration-tests:
runs-on: ubuntu-latest
name: Integration Tests 🧪
needs:
- test
steps:
- name: Checkout code 🛒
uses: actions/checkout@v4

- name: Setup bats 🦇
uses: bats-core/[email protected]
with:
bats-version: 1.11.0

- name: Download artifacts 📥
uses: actions/download-artifact@v4
with:
pattern: ebs-bootstrap-*
merge-multiple: true

- name: Make executable
shell: bash
run: |
set -euo pipefail
mv ebs-bootstrap-linux-x86_64 ebs-bootstrap
chmod +x ebs-bootstrap

- name: Setup tests ⚙️
run: bats bats/setup.bats

- name: Test ext4 🧪
run: bats bats/ext4.bats

- name: Test xfs 🧫
run: bats bats/xfs.bats

release:
if: ${{ github.ref_name == github.event.repository.default_branch }} # Only release from the default branch
runs-on: ubuntu-latest
name: Release 🚀
needs:
- test
- integration-tests
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3
- id: version
name: Get next version
uses: reecetech/[email protected]
- name: Checkout code 🛒
uses: actions/checkout@v4

- name: Download artifacts 📥
uses: actions/download-artifact@v4
with:
pattern: ebs-bootstrap-*
merge-multiple: true

- id: version
name: Get next version 🧮
uses: reecetech/[email protected]
with:
scheme: semver
increment: patch

- id: github-release
name: Create Github Release 📦
uses: softprops/action-gh-release@v0.1.15
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.v-version }}
prerelease: false
Expand All @@ -63,6 +107,7 @@ jobs:
generate_release_notes: true
files: |
*/ebs-bootstrap-linux-*

- id: push-short-tag
name: Create release short tag 🏷
uses: richardsimko/[email protected]
Expand Down
22 changes: 22 additions & 0 deletions bats/ext4.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats
# vim: set ft=sh sw=4 :

load helper_print-info

setup() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables in root of the repo visible to PATH
PATH="$DIR/../:$PATH"
}

@test "format & mount loop with ext4" {
run sudo $(command -v ebs-bootstrap) -config /tmp/ext4-bootstrap.yaml -mode force

print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"Successfully formatted /dev/loop"*" to ext4"* ]] &&
[[ "$output" = *"Successfully mounted /dev/loop"*" to /tmp/ext4"* ]]
}
9 changes: 9 additions & 0 deletions bats/helper_print-info.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# vim: set ft=sh sw=4 :

# shellcheck disable=SC2154

function print_run_info() {
echo "status: ${status}"
echo "output: ${output}"
}
65 changes: 65 additions & 0 deletions bats/setup.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bats
# vim: set ft=sh sw=4 :

load helper_print-info

setup() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables in root of the repo visible to PATH
PATH="$DIR/../:$PATH"
}

@test "setup loopback device for ext4" {
run bash -c '
dd if=/dev/zero of=/tmp/ext4-loop bs=4096 count=32768 \
&& sudo losetup -f /tmp/ext4-loop \
&& losetup --associated /tmp/ext4-loop 2>&1 | tee /tmp/losetup \
&& grep "/tmp/ext4-loop" /tmp/losetup | cut -d ':' -f 1 > /tmp/loopdev-ext4
'

print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"/tmp/ext4-loop"* ]]
}

@test "setup loopback device for xfs" {
run bash -c '
dd if=/dev/zero of=/tmp/xfs-loop bs=4096 count=32768 \
&& sudo losetup -f /tmp/xfs-loop \
&& losetup --associated /tmp/xfs-loop 2>&1 | tee /tmp/losetup \
&& grep "/tmp/xfs-loop" /tmp/losetup | cut -d ':' -f 1 > /tmp/loopdev-xfs
'

print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"/tmp/xfs-loop"* ]]
}

@test "setup ext4 config" {
echo """
---
devices:
$(cat /tmp/loopdev-ext4):
fs: ext4
mountPoint: /tmp/ext4
""" > /tmp/ext4-bootstrap.yaml

run mkdir /tmp/ext4
[ "$status" -eq 0 ]
}

@test "setup xfs config" {
echo """
---
devices:
$(cat /tmp/loopdev-xfs):
fs: xfs
mountPoint: /tmp/xfs
""" > /tmp/xfs-bootstrap.yaml

run mkdir /tmp/xfs
[ "$status" -eq 0 ]
}
22 changes: 22 additions & 0 deletions bats/xfs.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats
# vim: set ft=sh sw=4 :

load helper_print-info

setup() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables in root of the repo visible to PATH
PATH="$DIR/../:$PATH"
}

@test "format & mount loop with xfs" {
run sudo $(command -v ebs-bootstrap) -config /tmp/xfs-bootstrap.yaml -mode force

print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"Successfully formatted /dev/loop"*" to xfs"* ]] &&
[[ "$output" = *"Successfully mounted /dev/loop"*" to /tmp/xfs"* ]]
}
Loading