From 0f3a0e0fb2bcb75359dfbc48c1d7b158534df4db Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 4 Jan 2024 13:46:08 +0200 Subject: [PATCH] tests: add script to run a simple test This can be expanded Signed-off-by: Lars Wirzenius --- test.py | 18 ++++++++++++++++++ test.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100755 test.py create mode 100755 test.sh diff --git a/test.py b/test.py new file mode 100755 index 0000000..4c68396 --- /dev/null +++ b/test.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 + +import argparse +import json +import sys + + +p = argparse.ArgumentParser() +p.add_argument("--repo", default="rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE") +p.add_argument("--commit", required=True) +args = p.parse_args() + +trigger = { + "request": "trigger", + "repo": args.repo, + "commit": args.commit, +} +print(json.dumps(trigger)) diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..865f228 --- /dev/null +++ b/test.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -euo pipefail + +die() { + echo "$@" 2>&1 + exit 1 +} + +expect_failure() { + if cargo run -q <"$tmp/test-request.yaml" >"$tmp/test.stdout" 2>"$tmp/test.stderr"; then + echo "$tmp/test.log:" + cat "$tmp/test.log" + echo + echo "test.stdout:" + cat "$tmp/test.stdout" + echo + echo "test.stderr:" + cat "$tmp/test.stderr" + + die "success, when expected failure" + fi +} + +cargo build --all-targets --quiet + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +export TMPDIR="$tmp" + +cat <"$tmp/config.yaml" +state: $tmp/test.state +log: $tmp/test.log +EOF + +export RADICLE_NATIVE_CI="$tmp/test.yaml" +export RADICLE_NATIVE_CI_LOG=debug + +python3 test.py --commit b3a9a809420c89d08460046683f33d8a5bdfdc0a >"$tmp/test-request.yaml" +expect_failure + +echo All good.