Skip to content

Commit

Permalink
test: Add CI worfklow and example test
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy committed Nov 2, 2023
1 parent 8931d51 commit db6edb7
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: go
on:
push:
branches:
- main
pull_request:
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- run: make
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.wasm
bin
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
all: sqlc-gen-go sqlc-gen-go.wasm
.PHONY: build test

sqlc-gen-go:
cd plugin && go build -o ~/bin/sqlc-gen-go ./main.go
build:
go build ./...

sqlc-gen-go.wasm:
cd plugin && GOOS=wasip1 GOARCH=wasm go build -o sqlc-gen-go.wasm main.go
openssl sha256 plugin/sqlc-gen-go.wasm
test: bin/sqlc-gen-go.wasm
go test ./...

all: bin/sqlc-gen-go bin/sqlc-gen-go.wasm

bin/sqlc-gen-go: bin go.mod go.sum $(wildcard **/*.go)
cd plugin && go build -o ../bin/sqlc-gen-go ./main.go

bin/sqlc-gen-go.wasm: bin/sqlc-gen-go
cd plugin && GOOS=wasip1 GOARCH=wasm go build -o ../bin/sqlc-gen-go.wasm main.go

bin:
mkdir -p bin
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/authors/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions internal/endtoend/testdata/authors/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions internal/endtoend/testdata/authors/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions internal/endtoend/testdata/authors/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name;

-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING *;

-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1;
5 changes: 5 additions & 0 deletions internal/endtoend/testdata/authors/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
15 changes: 15 additions & 0 deletions internal/endtoend/testdata/authors/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '2'
plugins:
- name: golang
wasm:
url: file://../../../../bin/sqlc-gen-go.wasm
sql:
- schema: schema.sql
queries: query.sql
engine: postgresql
codegen:
- plugin: golang
out: go
options:
package: querytest
sql_package: pgx/v5

0 comments on commit db6edb7

Please sign in to comment.