From f29e5bc28bca4ba2564a1f230fdaff9befba6ef8 Mon Sep 17 00:00:00 2001 From: Mudassir Date: Sat, 26 Jul 2025 21:06:56 +0500 Subject: [PATCH 1/2] chore: added CI --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bb15881 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: ci + +on: + pull_request: + branches: + - main + - backend + +jobs: + tests: + name: Tests + runs-on: ubuntu-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' + + - name: Run unit tests + run: go test ./... -cover + + style: + name: Style + runs-on: ubuntu-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' + + - name: Check formatting + run: test -z $(go fmt ./...) + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Run staticcheck + run: staticcheck ./... From 028e99dc23eaeeb2d38338aba68a3f508911fefc Mon Sep 17 00:00:00 2001 From: Mudassir Date: Sun, 27 Jul 2025 00:51:13 +0500 Subject: [PATCH 2/2] chore: changed CI format --- .github/workflows/ci.yml | 35 ++++++++++++------------ internal/collections/collections_test.go | 31 +++++++++++++++++---- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb15881..594f627 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: ci +name: checks on: pull_request: @@ -7,9 +7,12 @@ on: - backend jobs: - tests: - name: Tests - runs-on: ubuntu-latest + 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 @@ -19,25 +22,21 @@ jobs: 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 - style: - name: Style - runs-on: ubuntu-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' + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest - - name: Check formatting - run: test -z $(go fmt ./...) + - name: Run gosec + run: gosec ./... - name: Install staticcheck run: go install honnef.co/go/tools/cmd/staticcheck@latest diff --git a/internal/collections/collections_test.go b/internal/collections/collections_test.go index 5a2bd30..9372370 100644 --- a/internal/collections/collections_test.go +++ b/internal/collections/collections_test.go @@ -3,7 +3,6 @@ package collections_test import ( "context" "database/sql" - "os" "testing" "github.com/maniac-en/req/internal/collections" @@ -11,6 +10,28 @@ import ( _ "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() @@ -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)