Skip to content
Open
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
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ node_modules/
!.yarn/versions
*.log
bin/

docker-compose.*
Makefile
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ COPY go.sum go.sum
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

ADD https://github.com/dnnrly/wait-for/releases/download/v0.0.1/wait-for_0.0.1_linux_386.tar.gz wait-for.tar.gz
RUN gunzip wait-for.tar.gz && tar -xf wait-for.tar && mv wait-for /usr/local/bin

ADD . .
RUN buffalo build --static -o /bin/app

Expand All @@ -30,6 +33,7 @@ RUN apk add --no-cache ca-certificates
WORKDIR /bin/

COPY --from=builder /bin/app .
COPY --from=builder /go/bin/buffalo .

# Uncomment to run the binary in "production" mode:
# ENV GO_ENV=production
Expand All @@ -40,5 +44,5 @@ ENV ADDR=0.0.0.0
EXPOSE 3000

# Uncomment to run the migrations before running the binary:
# CMD /bin/app migrate; /bin/app
CMD exec /bin/app
CMD /bin/app migrate; /bin/app
# CMD exec /bin/app
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


.PHONY: cucumber-test
cucumber-test:
docker compose -f docker-compose.yml up \
--build \
--remove-orphans \
--abort-on-container-exit \
--attach-dependencies \
tests

.PHONY: test
test:
docker compose -f docker-compose.yml up \
--build \
--remove-orphans \
--abort-on-container-exit \
--attach-dependencies \
tests

.PHONY: down-all
down-all:
docker compose -f docker-compose.yml down
# docker compose -f docker-compose.gherkin.yml down

.PHONY: ps-all
ps-all:
docker compose -f docker-compose.yml ps
# docker compose -f docker-compose.gherkin.yml ps
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,30 @@ There are some interesting features to be aware of:

</details>



<details>

<summary>Gherkin (Cucumber) tests</summary>

Now, if you're not familiar with it, [Gherkin](https://www.guru99.com/gherkin-test-cucumber.html)
is a format that allows you to specify the behaviour of your application in a way that it can
be read by normal humans. You may have encountered it by using [Cucumber](https://cucumber.io/).
I've found it a very powerful way of validating the behaviour of Buffalo app and other projects,
even CLI tools.

Why I specifically like these tests is that it forces you to think about the behaviour or your
application from a user's point of view and driving tests using a seperate runtime allows you
to test the entire built application as it will be delivered in to Production. With Buffalo
unit tests, you're still really reaching in to the application to test things in a way that
isn't quite the same as it's really used.

## Important files

* ...

## What's happening

...

</details>
5 changes: 5 additions & 0 deletions actions/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo-pop/v3/pop/popmw"
"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/envy"
csrf "github.com/gobuffalo/mw-csrf"
forcessl "github.com/gobuffalo/mw-forcessl"
Expand Down Expand Up @@ -87,6 +88,10 @@ func App() *buffalo.App {
users.GET("/{id}", UsersShow)
users.Middleware.Skip(Authorize, UsersNew, UsersCreate, UsersShow)

app.GET("/health", func(c buffalo.Context) error {
return c.Render(200, render.String("OK"))
})

app.ServeFiles("/", http.FS(public.FS())) // serve files from the public directory
}

Expand Down
26 changes: 14 additions & 12 deletions database.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
---
development:
dialect: postgres
database: buffalo_test_examples_development
user: postgres
password: postgres
host: 127.0.0.1
pool: 5
url: {{env "DEV_DATABASE_URL"}}
# dialect: {{envOr "DATABASE_DIALECT" "postgres"}}
# database: {{envOr "DATABASE_DB" "buffalo_test_examples_development"}}
# user: {{envOr "DATABASE_USER" "postgres"}}
# password: {{envOr "DATABASE_PASS" "postgres"}}
# host: {{envOr "DATABASE_HOST" "127.0.0.1"}}
# pool: {{envOr "DATABASE_POOL" "5"}}

test:
dialect: {{envOr "TEST_DATABASE_DIALECT" "postgres"}}
database: {{envOr "TEST_DATABASE_DB" "buffalo_test_examples_test"}}
user: {{envOr "TEST_DATABASE_USER" "postgres"}}
password: {{envOr "TEST_DATABASE_PASS" "postgres"}}
host: {{envOr "TEST_DATABASE_HOST" "127.0.0.1"}}
pool: {{envOr "TEST_DATABASE_POOL" "5"}}
url: {{env "TEST_DATABASE_URL"}}
# dialect: {{envOr "TEST_DATABASE_DIALECT" "postgres"}}
# database: {{envOr "TEST_DATABASE_DB" "buffalo_test_examples_test"}}
# user: {{envOr "TEST_DATABASE_USER" "postgres"}}
# password: {{envOr "TEST_DATABASE_PASS" "postgres"}}
# host: {{envOr "TEST_DATABASE_HOST" "127.0.0.1"}}
# pool: {{envOr "TEST_DATABASE_POOL" "5"}}

production:
url: {{env "DATABASE_URL"}}
47 changes: 39 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,54 @@ version: '3.1'

services:
db:
image: postgres
image: postgres:13.7
restart: always
environment:
POSTGRES_DB: buffalo_test_examples_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

tests:
image: gobuffalo/buffalo:v0.18.7
build: .
volumes:
- .:/project
working_dir: /project
environment:
# - TEST_DATABASE_URL=postgres://postgres:postgres@db:5432/buffalo_test_examples_test?sslmode=disable
- TEST_DATABASE_HOST=db
- TEST_DATABASE_DB=buffalo_test_examples_test
- TEST_DATABASE_USER=postgres
- TEST_DATABASE_PASS=postgres
- TEST_DATABASE_URL=postgres://postgres:postgres@db:5432/buffalo_test_examples_test?sslmode=disable
command: scripts/docker-test.sh
depends_on:
- db
- db

# web:
# build: .
# ports:
# - "3000"
# environment:
# - ADDR=0.0.0.0
# - PORT=3000
# - GO_ENV=test
# - TEST_DATABASE_URL=postgres://postgres:postgres@db:5432/buffalo_test_examples_test?sslmode=disable
# depends_on:
# - db

# gherkin:
# build:
# context: .
# dockerfile: tests.dockerfile
# command: >
# /bin/sh -c '
# set -eo xtrace

# wait-for -timeout 15s tcp:db:5432 http://web:3000

# pushd /project/test

# godog
# '
# volumes:
# - .:/project
# environment:
# - TEST_DATABASE_URL=postgres://postgres:postgres@db:5432/buffalo_test_examples_test?sslmode=disable
# depends_on:
# - db
# - web
19 changes: 13 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
module buffalo_test_examples

go 1.20
go 1.18

require (
github.com/antonmedv/expr v1.12.5
github.com/cucumber/godog v0.12.6
github.com/gobuffalo/buffalo v1.1.0
github.com/gobuffalo/buffalo-pop/v3 v3.0.7
github.com/gobuffalo/envy v1.10.2
github.com/gobuffalo/grift v1.5.2
github.com/gobuffalo/httptest v1.5.2
github.com/gobuffalo/mw-csrf v1.0.2
github.com/gobuffalo/mw-forcessl v1.0.2
github.com/gobuffalo/mw-i18n/v2 v2.0.3
github.com/gobuffalo/mw-paramlogger v1.0.2
github.com/gobuffalo/pop/v6 v6.1.1
github.com/gobuffalo/suite/v4 v4.0.4
github.com/gobuffalo/validate/v3 v3.3.3
github.com/gobuffalo/x v0.1.0
github.com/gofrs/uuid v4.3.1+incompatible
github.com/lib/pq v1.10.7
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.1
github.com/unrolled/secure v1.13.0
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
)

require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/antonmedv/expr v1.12.5 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
Expand All @@ -34,23 +41,24 @@ require (
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/gobuffalo/events v1.4.3 // indirect
github.com/gobuffalo/fizz v1.14.4 // indirect
github.com/gobuffalo/flect v1.0.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gobuffalo/github_flavored_markdown v1.1.3 // indirect
github.com/gobuffalo/helpers v0.6.7 // indirect
github.com/gobuffalo/httptest v1.5.2 // indirect
github.com/gobuffalo/logger v1.0.7 // indirect
github.com/gobuffalo/meta v0.3.3 // indirect
github.com/gobuffalo/middleware v1.0.0 // indirect
github.com/gobuffalo/nulls v0.4.2 // indirect
github.com/gobuffalo/plush/v4 v4.1.18 // indirect
github.com/gobuffalo/refresh v1.13.3 // indirect
github.com/gobuffalo/tags/v3 v3.1.4 // indirect
github.com/gobuffalo/x v0.1.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
Expand Down Expand Up @@ -80,7 +88,6 @@ require (
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.1 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.6.0 // indirect
Expand Down
Loading