Skip to content

Commit e976458

Browse files
authored
Merge pull request #625 from cgwalters/more-tests-2
tests: Add pytest and nushell based tests
2 parents b73b5f7 + 9a758e3 commit e976458

File tree

11 files changed

+86
-8
lines changed

11 files changed

+86
-8
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.cosa
22
target
33
!target/dev-rootfs
4+
# These directories don't contribute to our container build
5+
docs/
6+
plans/

.github/workflows/python.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Python static analysis
2+
on: [push, pull_request]
3+
jobs:
4+
ruff:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: chartboost/ruff-action@v1

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test-tmt:
3838
validate:
3939
cargo fmt
4040
cargo clippy
41+
ruff check
4142
.PHONY: validate
4243

4344
vendor:

hack/provision-derived.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
#!/bin/bash
22
set -xeu
3-
case "$1" in
3+
variant=$1
4+
# I'm a big fan of nushell for interactive use, and I want to support
5+
# using it in our test suite because it's better than bash. First,
6+
# enable EPEL to get it.
7+
. /usr/lib/os-release
8+
if echo $ID_LIKE $ID | grep -q centos; then
9+
dnf config-manager --set-enabled crb
10+
dnf -y install epel-release epel-next-release
11+
fi
12+
# Ensure this is pre-created
13+
mkdir -p -m 0700 /var/roothome
14+
mkdir -p ~/.config/nushell
15+
echo '$env.config = { show_banner: false, }' > ~/.config/nushell/config.nu
16+
touch ~/.config/nushell/env.nu
17+
dnf -y install nu
18+
# And we also add pytest, to support running tests written in Python
19+
dnf -y install python3-pytest
20+
case "$variant" in
421
tmt)
522
# tmt wants rsync
6-
dnf -y install cloud-init rsync && dnf clean all
23+
dnf -y install cloud-init rsync
724
ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants
825
# And tmt wants to write to /usr/local/bin
926
rm /usr/local -rf && ln -sr /var/usrlocal /usr/local && mkdir -p /var/usrlocal/bin
@@ -14,3 +31,4 @@ case "$1" in
1431
echo "Unknown variant: $1" exit 1
1532
;;
1633
esac
34+
dnf clean all && rm /var/log/* -rf

plans/integration-run.fmf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
# This tmt test just demonstrates local tmt usage.
2-
# We'll hopefully expand it to do more interesting things in the
3-
# future and unify with the other test plans.
1+
# Run this via `make test-tmt` which will build a container,
2+
# and a disk image from it.
43
provision:
54
how: virtual
6-
# Generated by `cargo xtask `
5+
# Generated by make test-tmt
76
image: file://./target/testvm/disk.qcow2
87
disk: 20
9-
summary: Basic smoke test
8+
summary: Execute booted tests
109
execute:
1110
how: tmt
12-
script: bootc status
11+
# There's currently two dynamic test frameworks; python and nushell.
12+
# python is well known and understood. nushell is less well known, but
13+
# is quite nice for running subprocesses and the like while making
14+
# it easy to parse JSON etc.
15+
script: |
16+
set -xeu
17+
pytest tests/booted/*.py
18+
ls tests/booted/*-test-*.nu |sort -n | while read t; do nu $t; done

tests/booted/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

tests/booted/001-test-status.nu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std assert
2+
use tap.nu
3+
4+
tap begin "verify bootc status --json looks sane"
5+
6+
let st = bootc status --json | from json
7+
assert equal $st.apiVersion org.containers.bootc/v1alpha1
8+
tap ok

tests/booted/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Booted tests
2+
3+
These are intended to run via tmt; use e.g.
4+
`make test-tmt`.

tests/booted/basic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tests which are read-only/nondestructive
2+
3+
import json
4+
import subprocess
5+
6+
def run(*args):
7+
subprocess.check_call(*args)
8+
9+
def test_bootc_status():
10+
o = subprocess.check_output(["bootc", "status", "--json"])
11+
st = json.loads(o)
12+
assert st['apiVersion'] == 'org.containers.bootc/v1alpha1'

tests/booted/tap.nu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# A simple nushell "library" for the
2+
# "Test anything protocol":
3+
# https://testanything.org/tap-version-14-specification.html
4+
export def begin [description] {
5+
print "TAP version 14"
6+
print $description
7+
}
8+
9+
export def ok [] {
10+
print "ok"
11+
}
12+
13+
export def fail [] {
14+
print "not ok"
15+
}

0 commit comments

Comments
 (0)