-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Migrate expect based test script to bats"
This reverts commit ac87c23. This change has to be in another PR, as per #4198 (comment)
- Loading branch information
Showing
1 changed file
with
139 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,156 @@ | ||
#!/usr/bin/env bats | ||
#!/bin/bash | ||
# | ||
# bats v0.4.0 project | ||
# References & examples for expect: | ||
# | ||
# https://github.com/sstephenson/bats/tree/v0.4.0 | ||
# - https://pantz.org/software/expect/expect_examples_and_tips.html | ||
# - https://stackoverflow.com/questions/13982310/else-string-matching-in-expect | ||
# - https://gist.github.com/Fluidbyte/6294378 | ||
# - https://www.oreilly.com/library/view/exploring-expect/9781565920903/ch04.html | ||
# | ||
# Prior to running this script, run: | ||
# | ||
# ./bisq-daemon --apiPassword=xyz | ||
# | ||
# To run this script: | ||
# | ||
# cd <project-root-dir> | ||
# bats cli/bats-test.sh | ||
# | ||
# The data directory used must contain an unencrypted wallet with a 0 BTC balance | ||
|
||
@test "test unsupported method error" { | ||
run ./bisq-cli --password=xyz bogus | ||
[ "$status" -eq 1 ] | ||
echo "actual output: $output" >&2 # printed only on test failure | ||
[ "$output" = "Error: 'bogus' is not a supported method" ] | ||
} | ||
# Ensure project root is the current working directory | ||
cd $(dirname $0)/.. | ||
|
||
OUTPUT=$(expect -c ' | ||
# exp_internal 1 | ||
puts "TEST unsupported cmd error" | ||
set expected "Error: '\''bogus'\'' is not a supported method" | ||
spawn ./bisq-cli --password=xyz bogus | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test unrecognized option error" { | ||
run ./bisq-cli --bogus getversion | ||
[ "$status" -eq 1 ] | ||
echo "actual output: $output" >&2 | ||
[ "$output" = "Error: bogus is not a recognized option" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
puts "TEST unrecognized option error" | ||
set expected "Error: bogus is not a recognized option" | ||
spawn ./bisq-cli --bogus getversion | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test missing required password option error" { | ||
run ./bisq-cli getversion | ||
[ "$status" -eq 1 ] | ||
echo "actual output: $output" >&2 | ||
[ "$output" = "Error: missing required 'password' option" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
# exp_internal 1 | ||
puts "TEST missing required password option error" | ||
set expected "Error: missing required '\''password'\'' option" | ||
spawn ./bisq-cli getversion | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test incorrect password error" { | ||
run ./bisq-cli --password=bogus getversion | ||
[ "$status" -eq 1 ] | ||
echo "actual output: $output" >&2 | ||
[ "$output" = "Error: incorrect 'password' rpc header value" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
# exp_internal 1 | ||
puts "TEST getversion (incorrect password error)" | ||
set expected "Error: incorrect '\''password'\'' rpc header value" | ||
spawn ./bisq-cli --password=bogus getversion | ||
expect { | ||
$expected { puts "PASS\n" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test getversion call with quoted password" { | ||
run ./bisq-cli --password="xyz" getversion | ||
[ "$status" -eq 0 ] | ||
echo "actual output: $output" >&2 | ||
[ "$output" = "1.3.2" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
# exp_internal 1 | ||
puts "TEST getversion (password value in quotes)" | ||
set expected "1.3.2" | ||
# Note: have to define quoted argument in a variable as "''value''" | ||
set pwd_in_quotes "''xyz''" | ||
spawn ./bisq-cli --password=$pwd_in_quotes getversion | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test getversion" { | ||
run ./bisq-cli --password=xyz getversion | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "1.3.2" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
puts "TEST getversion" | ||
set expected "1.3.2" | ||
spawn ./bisq-cli --password=xyz getversion | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test getbalance (available & unlocked wallet with 0 btc balance)" { | ||
run ./bisq-cli --password=xyz getbalance | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "0.00000000" ] | ||
} | ||
OUTPUT=$(expect -c ' | ||
puts "TEST getbalance" | ||
# exp_internal 1 | ||
set expected "0.00000000" | ||
spawn ./bisq-cli --password=xyz getbalance | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test help displayed on stderr if no options or arguments" { | ||
run ./bisq-cli | ||
[ "$status" -eq 1 ] | ||
[ "${lines[0]}" = "Bisq RPC Client" ] | ||
[ "${lines[1]}" = "Usage: bisq-cli [options] <method>" ] | ||
# TODO add asserts after help text is modified for new endpoints | ||
} | ||
OUTPUT=$(expect -c ' | ||
puts "TEST running with no options or arguments prints help text" | ||
# exp_internal 1 | ||
set expected "Bisq RPC Client" | ||
spawn ./bisq-cli | ||
expect { | ||
$expected { puts "PASS" } | ||
default { | ||
set results $expect_out(buffer) | ||
puts "FAIL expected = $expected" | ||
puts " actual = $results" | ||
} | ||
} | ||
') | ||
echo "$OUTPUT" | ||
echo "========================================================================" | ||
|
||
@test "test --help option" { | ||
run ./bisq-cli --help | ||
[ "$status" -eq 0 ] | ||
[ "${lines[0]}" = "Bisq RPC Client" ] | ||
[ "${lines[1]}" = "Usage: bisq-cli [options] <method>" ] | ||
# TODO add asserts after help text is modified for new endpoints | ||
} | ||
echo "TEST --help option prints help text" | ||
./bisq-cli --help |