gas-stack/ops/gas_init_test.sh
wispem-wantex 1c56661560
All checks were successful
CI / build-docker (push) Successful in 4s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Successful in 17s
codegen: add foreign key error check test
2026-02-01 08:04:12 -08:00

60 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# ------------------
# This is a test script that initializes a new project.
# ------------------
set -e
set -x
PS4='+(${BASH_SOURCE}:${LINENO}): '
proj_root=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")
cd "$proj_root"
# Compile `gas`
gas="/tmp/gas"
ops/compile.sh
mv gas $gas
test_project="/memory/test_gasproj"
if [[ -e $test_project ]]; then
rm -r "$test_project"
fi
$gas init "$test_project" <<EOF
mymodule
mydb.db
prog
EOF
cd $test_project
# Add "replace" directive"
echo "replace git.offline-twitter.com/offline-labs/gas-stack => $proj_root" >> go.mod
# Create a new table in the schema
cat >> pkg/db/schema.sql <<EOF
create table item_flavor (rowid integer primary key, name text not null) strict;
create table items (
rowid integer primary key,
description text not null default '',
flavor integer references item_flavor(rowid)
) strict;
EOF
# Generate an item model and test file
$gas generate items > pkg/db/item.go
$gas generate items --test > pkg/db/item_test.go
go mod tidy
# Run the tests
go test ./...
# Run sqlite_lint
$gas sqlite_lint pkg/db/schema.sql
# Notify success in green
echo -e "\033[32mAll tests passed. Finished successfully.\033[0m"