gas-stack/ops/gas_init_test.sh
~wispem-wantex 1bc7f9111f
Some checks failed
CI / build-docker (push) Successful in 6s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Failing after 16s
codegen: implement "without rowid" tables
2026-03-18 10:39:38 -07:00

72 lines
1.5 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),
data blob not null,
thing text not null unique,
created_at integer not null,
updated_at integer not null
) strict;
create table item_to_item (
item1_id integer references items(rowid),
item2_id integer references items(rowid),
primary key (item1_id, item2_id)
) strict, without rowid;
EOF
# Generate an item model and test file
$gas generate items > pkg/db/item.go
$gas generate items --test > pkg/db/item_test.go
$gas generate item_to_item > pkg/db/item_to_item.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"