diff --git a/.woodpecker/build.yaml b/.woodpecker/build.yaml index ed6dc9b..c9c6299 100644 --- a/.woodpecker/build.yaml +++ b/.woodpecker/build.yaml @@ -1,5 +1,5 @@ when: - - event: push + - event: [push, pull_request] branch: main steps: diff --git a/.woodpecker/lint.yaml b/.woodpecker/lint.yaml new file mode 100644 index 0000000..7bc2a63 --- /dev/null +++ b/.woodpecker/lint.yaml @@ -0,0 +1,9 @@ +when: + - event: [push, pull_request] + branch: main + +steps: + - name: build + image: golangci-lint + commands: + - golangci-lint run diff --git a/.woodpecker/test.yaml b/.woodpecker/test.yaml index 953b401..b218e79 100644 --- a/.woodpecker/test.yaml +++ b/.woodpecker/test.yaml @@ -1,5 +1,5 @@ when: - - event: push + - event: [push, pull_request] branch: main # go again @@ -13,3 +13,6 @@ steps: commands: - go get ./... - go test ./... -v + +depends_on: + - build diff --git a/cmd/main.go b/cmd/main.go index 81d34ca..92ee4f0 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -12,8 +12,8 @@ import ( todohandler "gitea.michaelthomson.dev/mthomson/habits/internal/todo/handler" todorepository "gitea.michaelthomson.dev/mthomson/habits/internal/todo/repository/postgres" todoservice "gitea.michaelthomson.dev/mthomson/habits/internal/todo/service" - _ "github.com/mattn/go-sqlite3" _ "github.com/jackc/pgx/v5/stdlib" + _ "github.com/mattn/go-sqlite3" ) func main() { @@ -27,7 +27,7 @@ func main() { postgresUrl := "postgres://todo:password@localhost:5432/todo" db, err := sql.Open("pgx", postgresUrl) if err != nil { - log.Fatal("Failed to open db pool") + log.Fatalf("Failed to open db pool: %v", err) } defer db.Close() @@ -51,9 +51,13 @@ func main() { // create server server := &http.Server{ - Addr: ":8080", + Addr: ":8080", Handler: mux, } - server.ListenAndServe() + err = server.ListenAndServe() + + if err != nil { + log.Fatalf("Failed to start server: %v", err) + } } diff --git a/internal/todo/repository/postgres/postgres_test.go b/internal/todo/repository/postgres/postgres_test.go index 0b734a6..325427e 100644 --- a/internal/todo/repository/postgres/postgres_test.go +++ b/internal/todo/repository/postgres/postgres_test.go @@ -16,11 +16,10 @@ import ( ) type TestDatabase struct { - Db *sql.DB + Db *sql.DB container testcontainers.Container } - func NewTestDatabase() *TestDatabase { ctx := context.Background() // create container @@ -33,7 +32,7 @@ func NewTestDatabase() *TestDatabase { wait.ForLog("database system is ready to accept connections"). WithOccurrence(2). WithStartupTimeout(5*time.Second)), - ) + ) if err != nil { log.Fatalf("Failed to create postgres container, %v\n", err) @@ -53,7 +52,7 @@ func NewTestDatabase() *TestDatabase { migrate.Migrate(db) return &TestDatabase{ - Db: db, + Db: db, container: postgresContainer, } }