Skip to content

Commit

Permalink
[feature] add script to test import / export cycle of a gotosocial in…
Browse files Browse the repository at this point in the history
…stance (superseriousbusiness#2693)

* add script to test import / export cycle of a gotosocial instance

* use suffix for setting mktemp file suffix
  • Loading branch information
NyaaaWhatsUpDoc authored Feb 27, 2024
1 parent 9bf448b commit 90dcc00
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions test/import-export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

set -ex

HOST='localhost:8080'
ADDR='127.0.0.1'
PORT='8080'
DB=$(mktemp)
STORAGE=$(mktemp -d)
EXPORT="$(mktemp --suffix '.json')"

_kill() {
pid=$(pidof gotosocial) \
|| return # i.e. not running
kill -$1 $pid
}

gotosocial() {
env \
GTS_HOST=$HOST \
GTS_PROTOCOL='http' \
GTS_BIND_ADDRESS=$ADDR \
GTS_PORT=$PORT \
GTS_DB_TYPE='sqlite' \
GTS_DB_ADDRESS=$DB \
GTS_STORAGE_BACKEND='local' \
GTS_STORAGE_LOCAL_BASE_PATH=$STORAGE \
GTS_WEB_ASSET_BASE_DIR='./web/assets' \
GTS_WEB_TEMPLATE_BASE_DIR='./web/template' \
go run ./cmd/gotosocial ${@}
}

# Cleanup instance, database file, export file, storage on exit
trap "_kill 9; rm -f $DB; rm -f $EXPORT; rm -rf $STORAGE" exit

# Iterate list of usernames
for username in scoobert \
shaggy \
daphne \
velma \
fred \
scrappy; do # hahaha

# Create account for each username
gotosocial admin account create \
--username ${username} \
--password 'sh1t_tiEr_Password Zomg123!' \
--email ${username}@example.com

# Confirm each of the accounts
gotosocial admin account confirm \
--username ${username}
done

# Ensure server runs once
gotosocial server start &

# Kill server
sleep 5
_kill 15
sleep 5

# Export current gts database to file
gotosocial admin export --path "$EXPORT" \
|| echo 'failed exporting to file'

# Clear database
rm -f $DB
touch $DB

# Import current gts database from file
gotosocial admin import --path "$EXPORT" \
|| echo 'failed importing from file'

# Ensure server can restart
{ gotosocial server start \
|| echo 'post-import failure'
} &

# Kill server
sleep 5
_kill 15
sleep 5

exit 0

0 comments on commit 90dcc00

Please sign in to comment.