Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Dec 20, 2023
1 parent 2f87531 commit b6a7833
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/bats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: Stefan Tatschner
#
# SPDX-License-Identifier: CC0-1.0

on: [push, pull_request]

jobs:
bats:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install bats
uses: brokenpip3/[email protected]
- name: run bats
run: |
bats -x -r tests
8 changes: 1 addition & 7 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
#
# SPDX-License-Identifier: CC0-1.0

on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]

name: "Linters"
permissions: {}
Expand Down
45 changes: 45 additions & 0 deletions tests/0001-invocation.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bats

# SPDX-FileCopyrightText: AISEC Pentesting Team
#
# SPDX-License-Identifier: Apache-2.0

setup() {
# https://bats-core.readthedocs.io/en/stable/tutorial.html#let-s-do-some-setup
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"
}

@test "invoke penrun without parameters" {
local tmpdir
tmpdir="$(mktemp -d)"
(
cd "$tmpdir"
penrun -c /dev/null ls -lah
if [[ ! -d "ls" ]]; then
echo "output directory is missing"
return 1
fi

mapfile -t meta < "ls/LATEST/META.json"
for line in "${meta[@]}"; do
local cmd
local exit_code
if [[ "$line" =~ EXIT:(.+) ]]; then
exit_code="${BASH_REMATCH[1]}"
if ((exit_code != 0)); then
return 1
fi
fi
if [[ "$line" =~ COMMAND:(.+)\s$ ]]; then
cmd="${BASH_REMATCH[1]}"
if [[ "$cmd" != "ls -lah" ]]; then
echo "$cmd"
return 1
fi
fi
done

rm -rf "$tmpdir"
)
}

0 comments on commit b6a7833

Please sign in to comment.