Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: checks

on:
pull_request:
branches:
- main
- backend

jobs:
build_and_check:
name: Build & Checks on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.4'
cache: true

- name: Check formatting
run: |
go fmt ./...
git diff --exit-code

- name: Run unit tests
run: go test ./... -cover

- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@latest

- name: Run gosec
run: gosec ./...

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...
31 changes: 26 additions & 5 deletions internal/collections/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@ package collections_test
import (
"context"
"database/sql"
"os"
"testing"

"github.com/maniac-en/req/internal/collections"
"github.com/maniac-en/req/internal/database"
_ "github.com/mattn/go-sqlite3"
)

const schema = `
CREATE TABLE collections (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE endpoints (
id INTEGER PRIMARY KEY AUTOINCREMENT,
collection_id INTEGER NOT NULL,
name TEXT NOT NULL,
method TEXT NOT NULL,
url TEXT NOT NULL,
headers TEXT DEFAULT '{}' NOT NULL,
query_params TEXT DEFAULT '{}' NOT NULL,
request_body TEXT DEFAULT '' NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (collection_id) REFERENCES collections(id) ON DELETE CASCADE
);
`

func setupTestDB(t *testing.T) (*sql.DB, *database.Queries, func()) {
t.Helper()

Expand All @@ -19,10 +40,10 @@ func setupTestDB(t *testing.T) (*sql.DB, *database.Queries, func()) {
t.Fatalf("failed to open test db: %v", err)
}

schema, err := os.ReadFile("testdata/schema.sql")
if err != nil {
t.Fatalf("failed to read schema: %v", err)
}
// schema, err := os.ReadFile("testdata/schema.sql")
// if err != nil {
// t.Fatalf("failed to read schema: %v", err)
// }
_, err = db.Exec(string(schema))
if err != nil {
t.Fatalf("failed to execute schema: %v", err)
Expand Down
Loading