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