Skip to content
Merged
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
9 changes: 9 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:1.26-bookworm

Check warning on line 1 in .devcontainer/Dockerfile

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The "golang" image runs with "root" as the default user. Make sure it is safe here.

See more on https://sonarcloud.io/project/issues?id=IDTS-LAB_go-codebase&issues=AZ9kD7JLkHs2w76SOVNC&open=AZ9kD7JLkHs2w76SOVNC&pullRequest=3

RUN apt-get update && apt-get install -y --no-install-recommends \

Check warning on line 3 in .devcontainer/Dockerfile

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this RUN instruction with the consecutive ones.

See more on https://sonarcloud.io/project/issues?id=IDTS-LAB_go-codebase&issues=AZ9kD7JLkHs2w76SOVNB&open=AZ9kD7JLkHs2w76SOVNB&pullRequest=3
postgresql-client \
&& rm -rf /var/lib/apt/lists/*

RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest && \
go install github.com/swaggo/swag/cmd/swag@latest && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
32 changes: 32 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "go-codebase",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-from-docker:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"ms-azuretools.vscode-docker"
]
}
},
"forwardPorts": [5432],
"portsAttributes": {
"5432": {
"label": "PostgreSQL"
}
},
"remoteEnv": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_USER": "postgres",
"DB_PASSWORD": "postgres",
"DB_NAME": "codebase_testing",
"DB_SSLMODE": "disable"
},
"postCreateCommand": "go mod download"
}
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: go_codebase_test
POSTGRES_DB: codebase_testing
ports:
- 5432:5432
options: >-
Expand Down Expand Up @@ -109,11 +109,11 @@ jobs:
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: go_codebase_test
DB_NAME: codebase_testing
DB_SSLMODE: disable
REDIS_ADDR: localhost:6379
JWT_SECRET: test-secret-key-not-for-production
run: go test -race -count=1 ./...
run: go test -race -count=1 -v ./...

build:
name: Build
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: run build test lint fmt migrate-up migrate-down sqlc swagger docker-up docker-down docker-dev docker-dev-down clean rename install-tools precommit install-hooks
.PHONY: run build test test-unit test-integration lint fmt migrate-up migrate-down sqlc swagger docker-up docker-down docker-dev docker-dev-down clean rename install-tools precommit install-hooks

APP_NAME := go-codebase
BUILD_DIR := bin
Expand Down Expand Up @@ -37,6 +37,12 @@ build:
test:
go test -v -count=1 ./...

test-unit:
go test -v -count=1 $(shell go list ./... | grep -v /tests/)

test-integration:
go test -v -count=1 $(shell go list ./... | grep /tests/)

test-coverage:
go test -v -count=1 -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.8"

# Test infrastructure — standalone PostgreSQL for running integration tests.
# Start before running tests:
# docker compose -f docker-compose.test.yml up -d
# Then run:
# go test -count=1 ./...
#
# Override DB_NAME via environment:
# DB_NAME=my_test_db docker compose -f docker-compose.test.yml up -d

services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ${DB_NAME:-codebase_testing}
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
30 changes: 17 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ require (
github.com/knadh/koanf/v2 v2.1.1
github.com/lib/pq v1.10.9
github.com/nats-io/nats.go v1.37.0
github.com/pressly/goose/v3 v3.27.2
github.com/prometheus/client_golang v1.23.2
github.com/redis/go-redis/v9 v9.7.0
github.com/rs/cors v1.11.0
github.com/sendgrid/sendgrid-go v3.16.1+incompatible
github.com/stretchr/testify v1.11.1
github.com/swaggo/http-swagger v1.3.4
github.com/swaggo/swag v1.16.6
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.31.0
go.opentelemetry.io/otel/sdk v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
go.opentelemetry.io/otel/sdk v1.43.0
go.opentelemetry.io/otel/trace v1.43.0
go.uber.org/fx v1.23.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.53.0
Expand All @@ -41,7 +42,7 @@ require (
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v1.0.0 // indirect
github.com/go-openapi/jsonreference v1.0.0 // indirect
Expand All @@ -57,9 +58,10 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/compress v1.18.5 // indirect
github.com/knadh/koanf/maps v0.1.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand All @@ -68,15 +70,17 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
github.com/sendgrid/rest v2.6.9+incompatible // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/stretchr/objx v0.5.3 // indirect
github.com/swaggo/files v1.0.1 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/metric v1.43.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.37.0 // indirect
Expand All @@ -85,9 +89,9 @@ require (
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.39.0 // indirect
golang.org/x/tools v0.47.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.36.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260120221211-b8f7ae30c516 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260420184626-e10c466a9529 // indirect
google.golang.org/grpc v1.80.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading