tests: add extra_tests argument to scenario lib run_tests()
This commit is contained in:
parent
6f9349b0a4
commit
5fa0602a18
@ -1,25 +1,36 @@
|
||||
run_tests()
|
||||
def electrs():
|
||||
machine.wait_for_open_port(4224) # prometeus metrics provider
|
||||
|
||||
## electrs
|
||||
# the main test body stops electrs
|
||||
succeed("systemctl start electrs")
|
||||
machine.wait_for_open_port(4224) # prometeus metrics provider
|
||||
|
||||
## spark-wallet
|
||||
machine.wait_for_open_port(9737)
|
||||
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
|
||||
assert_matches(f"curl -s {spark_auth}@localhost:9737", "Spark")
|
||||
def spark_wallet():
|
||||
machine.wait_for_open_port(9737)
|
||||
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
|
||||
assert_matches(f"curl -s {spark_auth}@localhost:9737", "Spark")
|
||||
|
||||
## lightning-charge
|
||||
machine.wait_for_open_port(9112)
|
||||
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
|
||||
assert_matches(f"curl -s api-token:{charge_auth}@localhost:9112/info | jq", '"id"')
|
||||
|
||||
## nanopos
|
||||
machine.wait_for_open_port(9116)
|
||||
assert_matches("curl localhost:9116", "tshirt")
|
||||
def lightning_charge():
|
||||
machine.wait_for_open_port(9112)
|
||||
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
|
||||
assert_matches(f"curl -s api-token:{charge_auth}@localhost:9112/info | jq", '"id"')
|
||||
|
||||
## web index
|
||||
machine.wait_for_open_port(80)
|
||||
assert_matches("curl localhost", "nix-bitcoin")
|
||||
assert_matches("curl -L localhost/store", "tshirt")
|
||||
|
||||
def nanopos():
|
||||
machine.wait_for_open_port(9116)
|
||||
assert_matches("curl localhost:9116", "tshirt")
|
||||
|
||||
|
||||
def web_index():
|
||||
machine.wait_for_open_port(80)
|
||||
assert_matches("curl localhost", "nix-bitcoin")
|
||||
assert_matches("curl -L localhost/store", "tshirt")
|
||||
|
||||
|
||||
extra_tests = {
|
||||
"electrs": electrs,
|
||||
"spark-wallet": spark_wallet,
|
||||
"lightning-charge": lightning_charge,
|
||||
"nanopos": nanopos,
|
||||
"web-index": web_index,
|
||||
}
|
||||
|
||||
run_tests(extra_tests)
|
||||
|
@ -35,8 +35,9 @@ if "is_interactive" in vars():
|
||||
|
||||
### Tests
|
||||
|
||||
|
||||
def run_tests():
|
||||
# The argument extra_tests is a dictionary from strings to functions. The string
|
||||
# determines at which point of run_tests the corresponding function is executed.
|
||||
def run_tests(extra_tests):
|
||||
assert_running("setup-secrets")
|
||||
# Unused secrets should be inaccessible
|
||||
succeed('[[ $(stat -c "%U:%G %a" /secrets/dummy) = "root:root 440" ]]')
|
||||
@ -55,6 +56,7 @@ def run_tests():
|
||||
)
|
||||
|
||||
assert_running("electrs")
|
||||
extra_tests.pop("electrs")()
|
||||
# Check RPC connection to bitcoind
|
||||
machine.wait_until_succeeds(log_has_string("electrs", "NetworkInfo"))
|
||||
assert_running("nginx")
|
||||
@ -70,10 +72,13 @@ def run_tests():
|
||||
assert_matches("su operator -c 'lightning-cli getinfo' | jq", '"id"')
|
||||
|
||||
assert_running("spark-wallet")
|
||||
extra_tests.pop("spark-wallet")()
|
||||
|
||||
assert_running("lightning-charge")
|
||||
extra_tests.pop("lightning-charge")()
|
||||
|
||||
assert_running("nanopos")
|
||||
extra_tests.pop("nanopos")()
|
||||
|
||||
assert_running("onion-chef")
|
||||
|
||||
@ -81,6 +86,7 @@ def run_tests():
|
||||
# to incomplete unit dependencies.
|
||||
# 'create-web-index' implicitly tests 'nodeinfo'.
|
||||
machine.wait_for_unit("create-web-index")
|
||||
extra_tests.pop("web-index")()
|
||||
|
||||
machine.wait_until_succeeds(log_has_string("bitcoind-import-banlist", "Importing node banlist"))
|
||||
assert_no_failure("bitcoind-import-banlist")
|
||||
@ -128,3 +134,6 @@ def run_tests():
|
||||
### Stop lnd and restart clightning
|
||||
succeed("systemctl stop lnd")
|
||||
succeed("systemctl start " + stopped_services)
|
||||
|
||||
### Check that all extra_tests have been run
|
||||
assert len(extra_tests) == 0
|
||||
|
@ -1,5 +1,3 @@
|
||||
run_tests()
|
||||
|
||||
# netns IP addresses
|
||||
bitcoind_ip = "169.254.1.12"
|
||||
clightning_ip = "169.254.1.13"
|
||||
@ -13,38 +11,51 @@ recurringdonations_ip = "169.254.1.20"
|
||||
nginx_ip = "169.254.1.21"
|
||||
|
||||
## electrs
|
||||
# the main test body stops electrs
|
||||
succeed("systemctl start electrs")
|
||||
machine.wait_until_succeeds(
|
||||
def electrs():
|
||||
machine.wait_until_succeeds(
|
||||
"ip netns exec nb-electrs nc -z localhost 4224"
|
||||
) # prometeus metrics provider
|
||||
) # prometeus metrics provider
|
||||
|
||||
## spark-wallet
|
||||
machine.wait_until_succeeds("ip netns exec nb-spark-wallet nc -z %s 9737" % sparkwallet_ip)
|
||||
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
|
||||
assert_matches(
|
||||
|
||||
def spark_wallet():
|
||||
machine.wait_until_succeeds("ip netns exec nb-spark-wallet nc -z %s 9737" % sparkwallet_ip)
|
||||
spark_auth = re.search("login=(.*)", succeed("cat /secrets/spark-wallet-login"))[1]
|
||||
assert_matches(
|
||||
f"ip netns exec nb-spark-wallet curl -s {spark_auth}@%s:9737" % sparkwallet_ip, "Spark"
|
||||
)
|
||||
)
|
||||
|
||||
## lightning-charge
|
||||
machine.wait_until_succeeds("ip netns exec nb-nanopos nc -z %s 9112" % lightningcharge_ip)
|
||||
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
|
||||
assert_matches(
|
||||
|
||||
def lightning_charge():
|
||||
machine.wait_until_succeeds("ip netns exec nb-nanopos nc -z %s 9112" % lightningcharge_ip)
|
||||
charge_auth = re.search("API_TOKEN=(.*)", succeed("cat /secrets/lightning-charge-env"))[1]
|
||||
assert_matches(
|
||||
f"ip netns exec nb-nanopos curl -s api-token:{charge_auth}@%s:9112/info | jq"
|
||||
% lightningcharge_ip,
|
||||
'"id"',
|
||||
)
|
||||
)
|
||||
|
||||
## nanopos
|
||||
machine.wait_until_succeeds("ip netns exec nb-lightning-charge nc -z %s 9116" % nanopos_ip)
|
||||
assert_matches("ip netns exec nb-lightning-charge curl %s:9116" % nanopos_ip, "tshirt")
|
||||
|
||||
## webindex
|
||||
machine.wait_until_succeeds("ip netns exec nb-nginx nc -z localhost 80")
|
||||
assert_matches("ip netns exec nb-nginx curl localhost", "nix-bitcoin")
|
||||
assert_matches("ip netns exec nb-nginx curl -L localhost/store", "tshirt")
|
||||
def nanopos():
|
||||
machine.wait_until_succeeds("ip netns exec nb-lightning-charge nc -z %s 9116" % nanopos_ip)
|
||||
assert_matches("ip netns exec nb-lightning-charge curl %s:9116" % nanopos_ip, "tshirt")
|
||||
|
||||
|
||||
def web_index():
|
||||
machine.wait_until_succeeds("ip netns exec nb-nginx nc -z localhost 80")
|
||||
assert_matches("ip netns exec nb-nginx curl localhost", "nix-bitcoin")
|
||||
assert_matches("ip netns exec nb-nginx curl -L localhost/store", "tshirt")
|
||||
|
||||
|
||||
extra_tests = {
|
||||
"electrs": electrs,
|
||||
"spark-wallet": spark_wallet,
|
||||
"lightning-charge": lightning_charge,
|
||||
"nanopos": nanopos,
|
||||
"web-index": web_index,
|
||||
}
|
||||
|
||||
run_tests(extra_tests)
|
||||
|
||||
### Security tests
|
||||
|
||||
ping_bitcoind = "ip netns exec nb-bitcoind ping -c 1 -w 1"
|
||||
|
Loading…
Reference in New Issue
Block a user