From 67407220c33e956f796efb9fb5d910faf3511d25 Mon Sep 17 00:00:00 2001 From: Efremenko Arhip Date: Sun, 26 Jul 2026 16:27:24 +0300 Subject: [PATCH] ci(users): add pipeline (vet, gofmt, race, lint, migrate, integration) Mirrors the coordinator workflow against a scimesh_users Postgres service. Switches the test request helper to http.NewRequestWithContext so the noctx linter passes on the go1.22 module. --- .github/workflows/users.yml | 66 ++++++++++++++++++++ users/internal/transport/http/server_test.go | 5 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/users.yml diff --git a/.github/workflows/users.yml b/.github/workflows/users.yml new file mode 100644 index 0000000..e9620b8 --- /dev/null +++ b/.github/workflows/users.yml @@ -0,0 +1,66 @@ +name: users + +on: + push: + paths: + - "users/**" + - ".github/workflows/users.yml" + pull_request: + paths: + - "users/**" + - ".github/workflows/users.yml" + +defaults: + run: + working-directory: users + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_USER: scimesh + POSTGRES_PASSWORD: scimesh + POSTGRES_DB: scimesh_users + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U scimesh" + --health-interval 5s + --health-timeout 3s + --health-retries 10 + + env: + TEST_DATABASE_URL: postgres://scimesh:scimesh@localhost:5432/scimesh_users?sslmode=disable + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: users/go.mod + cache-dependency-path: users/go.sum + + - name: go vet + run: go vet ./... + + - name: gofmt + run: test -z "$(gofmt -l .)" || (gofmt -l . && exit 1) + + - name: unit tests (race) + run: go test -race ./... + + - name: lint + run: go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 run --build-tags=integration ./... + + - name: install migrate CLI + run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@v4.17.1 + + - name: apply migrations + run: migrate -path migrations -database "$TEST_DATABASE_URL" up + + - name: integration tests + run: go test -tags=integration ./internal/storage/postgres/ -v diff --git a/users/internal/transport/http/server_test.go b/users/internal/transport/http/server_test.go index a81a128..2ec04fa 100644 --- a/users/internal/transport/http/server_test.go +++ b/users/internal/transport/http/server_test.go @@ -47,7 +47,10 @@ func do(t *testing.T, h http.Handler, method, path, token string, body any) *htt t.Fatal(err) } } - req := httptest.NewRequest(method, path, &buf) + req, err := http.NewRequestWithContext(context.Background(), method, path, &buf) + if err != nil { + t.Fatal(err) + } if token != "" { req.Header.Set("Authorization", "Bearer "+token) }