nuno revisou este gist 1 month ago. Ir para a revisão
1 file changed, 88 insertions
fn.sh(arquivo criado)
| @@ -0,0 +1,88 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | # test/fn.sh — individual function test blocks | |
| 3 | + | # Sourced by test.command.sh — do not execute directly. | |
| 4 | + | # Requires run_cmd / run_cmd_fails from integration.sh to be sourced first. | |
| 5 | + | ||
| 6 | + | function cmd::test::run_function() { | |
| 7 | + | local fn="$1" | |
| 8 | + | case "$fn" in | |
| 9 | + | cmd::block::run) cmd::test::fn_block ;; | |
| 10 | + | cmd::unblock::run) cmd::test::fn_unblock ;; | |
| 11 | + | cmd::remove::run) cmd::test::fn_remove ;; | |
| 12 | + | cmd::rename::run) cmd::test::fn_rename ;; | |
| 13 | + | cmd::rule::assign) cmd::test::fn_rule_assign ;; | |
| 14 | + | *) | |
| 15 | + | log::error "No function test defined for: ${fn}" | |
| 16 | + | return 1 | |
| 17 | + | ;; | |
| 18 | + | esac | |
| 19 | + | } | |
| 20 | + | ||
| 21 | + | function cmd::test::fn_block() { | |
| 22 | + | test::section "cmd::block::run" | |
| 23 | + | ||
| 24 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 25 | + | "$WGCTL_BINARY" add --name testunit --type phone > /dev/null 2>&1 | |
| 26 | + | ||
| 27 | + | cmd::test::run_cmd "block peer" "blocked" block --name phone-testunit | |
| 28 | + | cmd::test::run_cmd "block already blocked" "already" block --name phone-testunit | |
| 29 | + | "$WGCTL_BINARY" unblock --name phone-testunit > /dev/null 2>&1 || true | |
| 30 | + | cmd::test::run_cmd "block with --type" "blocked" block --name testunit --type phone | |
| 31 | + | cmd::test::run_cmd_fails "block nonexistent" block --name truly-nonexistent-xyz | |
| 32 | + | ||
| 33 | + | "$WGCTL_BINARY" unblock --name phone-testunit > /dev/null 2>&1 || true | |
| 34 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 35 | + | } | |
| 36 | + | ||
| 37 | + | function cmd::test::fn_unblock() { | |
| 38 | + | test::section "cmd::unblock::run" | |
| 39 | + | ||
| 40 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 41 | + | "$WGCTL_BINARY" add --name testunit --type phone > /dev/null 2>&1 | |
| 42 | + | "$WGCTL_BINARY" block --name phone-testunit > /dev/null 2>&1 | |
| 43 | + | ||
| 44 | + | cmd::test::run_cmd "unblock peer" "unblocked" unblock --name phone-testunit | |
| 45 | + | cmd::test::run_cmd "unblock not blocked" "not blocked" unblock --name phone-testunit | |
| 46 | + | cmd::test::run_cmd_fails "unblock nonexistent" unblock --name nonexistent-peer | |
| 47 | + | cmd::test::run_cmd_fails "unblock missing --name" unblock | |
| 48 | + | ||
| 49 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 50 | + | } | |
| 51 | + | ||
| 52 | + | function cmd::test::fn_remove() { | |
| 53 | + | test::section "cmd::remove::run" | |
| 54 | + | ||
| 55 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 56 | + | "$WGCTL_BINARY" add --name testunit --type phone > /dev/null 2>&1 | |
| 57 | + | ||
| 58 | + | cmd::test::run_cmd "remove with --force" "removed" remove --name phone-testunit --force | |
| 59 | + | cmd::test::run_cmd_fails "remove nonexistent" remove --name nonexistent-peer --force | |
| 60 | + | cmd::test::run_cmd_fails "remove missing --name" remove --force | |
| 61 | + | } | |
| 62 | + | ||
| 63 | + | function cmd::test::fn_rename() { | |
| 64 | + | test::section "cmd::rename::run" | |
| 65 | + | ||
| 66 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 67 | + | "$WGCTL_BINARY" remove --name phone-testunit2 --force > /dev/null 2>&1 || true | |
| 68 | + | "$WGCTL_BINARY" add --name testunit --type phone > /dev/null 2>&1 | |
| 69 | + | ||
| 70 | + | cmd::test::run_cmd "rename peer" "renamed" rename --name phone-testunit --new-name phone-testunit2 | |
| 71 | + | cmd::test::run_cmd_fails "rename to existing" rename --name phone-testunit2 --new-name phone-nuno | |
| 72 | + | cmd::test::run_cmd_fails "rename nonexistent" rename --name phone-nonexistent --new-name phone-testunit | |
| 73 | + | cmd::test::run_cmd_fails "rename missing --new-name" rename --name phone-testunit2 | |
| 74 | + | ||
| 75 | + | "$WGCTL_BINARY" remove --name phone-testunit2 --force > /dev/null 2>&1 || true | |
| 76 | + | } | |
| 77 | + | ||
| 78 | + | function cmd::test::fn_rule_assign() { | |
| 79 | + | test::section "cmd::rule::assign" | |
| 80 | + | ||
| 81 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 82 | + | "$WGCTL_BINARY" add --name testunit --type phone > /dev/null 2>&1 | |
| 83 | + | ||
| 84 | + | cmd::test::run_cmd "rule assign" "Assigned" \ | |
| 85 | + | rule assign --name admin --peer phone-testunit | |
| 86 | + | ||
| 87 | + | "$WGCTL_BINARY" remove --name phone-testunit --force > /dev/null 2>&1 || true | |
| 88 | + | } | |
Próximo
Anterior