Files
SpacetimeDB/test/lib.include
T
Phoebe Goldman a1e9984840 Multiple server configurations for CLI (#214)
Alters the CLI's configuration format to support storing multiple server configurations,
and having each server configuration store an (optional) default identity.
Many CLI commands take an additional -s argument, the server on which to operate,
which defaults to the configured default_server.
Using -s consistently requires renaming the publish skip-clippy short flag to -S.

Per discussion with @jdetter , this PR does not directly associate identities with servers.
Instead, each server configuration stores the server's "fingerprint" (i.e. PEM-formatted ECDSA public key),
and the CLI uses that public key to decode tokens to determine if they apply to a given server.
This architecture allows the CLI to behave reasonably
when multiple server configurations use the same set of tokens,
e.g. if multiple distinct URLs resolve to the same SpacetimeDB instance.
For example, one could imagine a configuration with server configurations for both http://127.0.0.1:3000
and http://localhost:3000, which should use the same set of identities.
2023-09-01 17:29:20 +00:00

83 lines
1.5 KiB
Bash

#!/bin/bash
# Runs a test with the assumption that it will return a zero result code
run_test() {
set +e
"$@" > "$TEST_OUT" 2>&1
RESULT=$?
cat "$TEST_OUT"
set -e
return "$RESULT"
}
# Runs a test with the assumption that it will return a non-zero result code
run_fail_test() {
if "$@" > "$TEST_OUT" 2>&1 ; then
cat "$TEST_OUT"
return 1
fi
cat "$TEST_OUT"
return 0
}
# This resets the spacetime config for a new test run
reset_config() {
SPACETIME_CONFIG_FILE="$(mktemp)"
export SPACETIME_CONFIG_FILE
cp "$RESET_SPACETIME_CONFIG" "$SPACETIME_CONFIG_FILE"
}
# This deletes the project from the previous test run
reset_project() {
PROJECT_PATH="$(mktemp -d)"
rmdir "$PROJECT_PATH"
cp -rp "$RESET_PROJECT_PATH" "$PROJECT_PATH"
export PROJECT_PATH
}
# This cleans up the temporary project directory after a test
clear_project() {
rm -rf "$PROJECT_PATH"
}
# This cleans up the temporary config file after a test
clear_config() {
rm -f "$SPACETIME_CONFIG_FILE"
}
random_string() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo $RANDOM | md5 -q | head -c 20
else
echo $RANDOM | md5sum | head -c 20
fi
}
spacetime_publish() {
RETURN_DIR=$PWD
cd "$SPACETIME_DIR"
set +e
run_test spacetime publish "$@"
RESULT_CODE=$?
cd "$RETURN_DIR" || exit 1
set -e
return "$RESULT_CODE"
}
fsed() {
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i.sed_bak "$@"
rm -f rm *.sed_bak
else
sed -i "$@"
fi
}
restart_docker() {
docker-compose stop node
docker-compose start node
sleep 10
}
# vim: noexpandtab tabstop=4 shiftwidth=4