Skip to content

Commit

Permalink
Merge pull request #2 from scrabblett/feature/functional-tests
Browse files Browse the repository at this point in the history
add new handlers, functional tests
  • Loading branch information
scrabblett authored Apr 18, 2024
2 parents 1ef245d + d6c04de commit b1109e8
Show file tree
Hide file tree
Showing 42 changed files with 1,298 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=12345
POSTGRES_DB=books_library
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?sslmode=disable
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}?sslmode=disable
HTTP_SERVER_ADDRESS=localhost
HTTP_SERVER_PORT=8080
HTTP_SERVER_TIMEOUT=5s
HTTP_SERVER_TIMEOUT=15s
HTTP_SERVER_IDLE_TIMEOUT=60s
PGDATA=/data/postgres
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.idea
*.log
*.db
*.db
cover.out
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM golang:latest
LABEL authors="Dmitry Sagan"
LABEL description="Simple api written in Go. For any questions: telegram @quryy"

WORKDIR /app
COPY . .

RUN go install github.com/pressly/goose/v3/cmd/goose@latest
RUN go build ./cmd/app/main.go
# Install linter
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2

# Run makefile
RUN make all

# Run backend
CMD ["go run ./cmd/app/main.go"]
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
all: deps vet fmt tools lint deps mocks test test_coverage

deps:
@echo Install dependencies
go mod tidy
go mod download

vet:
go vet ./...

fmt:
@echo "$(OK_COLOR)Check fmt$(NO_COLOR)"
@echo "FIXME go fmt does not format imports, should be fixed"
@go fmt ./...

tools:
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/vektra/mockery/[email protected]
go get golang.org/x/tools/cmd/cover

lint:
golangci-lint run -enable-all

mocks:
go generate ./...

test:
go test ./... -coverprofile cover.out

test_coverage:
go tool cover -html cover.out
9 changes: 4 additions & 5 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main

import "simple-golang-api/internal/app"
import (
"simple-golang-api/internal/app"
)

func main() {
app.Run()

//toDo: cache requests, functional tests
//toDo: add pagination for books methods in handler
//toDo: work with context
//toDO: refactor unit-tests, mocks for integration tests
}
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ services:
interval: 5s
timeout: 10s
retries: 5
networks:
- api-network

backend:
ports:
- '8080:8080'
build:
dockerfile: Dockerfile
env_file:
Expand All @@ -23,4 +27,9 @@ services:
- ./cmd/app/main.go
depends_on:
postgres:
condition: service_healthy
condition: service_healthy
networks:
- api-network
networks:
api-network:
name: backend-network
25 changes: 25 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module simple-golang-api
go 1.22

require (
github.com/brianvoe/gofakeit/v7 v7.0.2
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/render v1.0.3
github.com/go-playground/validator/v10 v10.19.0
Expand All @@ -17,15 +19,38 @@ require (
require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.32.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.21.0 // indirect
Expand Down
Loading

0 comments on commit b1109e8

Please sign in to comment.