workspaces-pipelines/tests/test_validate_command_access.sh

67 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
cat >access.yml <<EOF
pallav:
fixedArgsCommands:
build:
- base
- workspace
- all
update:
- access
clean:
status:
multiArgsCommands:
remove:
- pallav
- palak
- param
- darshan
arbitArgsCommands:
- rmi
EOF
source ./validate_command_access.sh
testcase() {
local desc="$1"
shift
if validate_command pallav "$@"; then
echo "PASS: $desc"
else
echo "FAIL: $desc"
fi
}
# ----- Fixed Args Commands -----
testcase "build base (valid)" build base
testcase "build all (valid)" build all
testcase "build base workspace (invalid)" build base workspace || true
testcase "build (no arg, invalid)" build || true
testcase "update access (valid)" update access
testcase "clean (zero-arg, valid)" clean
testcase "clean with arg (invalid)" clean foo || true
testcase "status (zero-arg, valid)" status
testcase "status foo (invalid)" status foo || true
# ----- Multi Args Commands -----
testcase "remove palak (valid)" remove palak
testcase "remove param palak (valid, any order)" remove param palak
testcase "remove palak param darshan (valid, any order)" remove palak param darshan
testcase "remove pallav (valid)" remove pallav -f
testcase "remove (no arg, invalid)" remove || true
testcase "remove foo (invalid)" remove foo || true
testcase "remove palak palak (duplicate, invalid)" remove palak palak || true
# ----- Arbitrary Args Commands -----
testcase "rmi no args (valid)" rmi
testcase "rmi one arg (valid)" rmi image1
testcase "rmi multiple args (valid)" rmi image1 image2 image3
testcase "rmi with flag (valid)" rmi -f image1 image2
testcase "rmi with only flag (valid)" rmi -f
# ----- Disallowed command -----
testcase "foo (invalid command)" foo image1 # should fail