diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index ec24679..973b698 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,6 +20,7 @@ env: GOMODCACHE: /home/runner/go/mod GOPROXY: https://proxy.golang.org GOTOOLCHAIN: local + MONGODB_URI: mongodb://localhost:27017/ # TODO https://github.com/FerretDB/wire/issues/9 GOEXPERIMENT: rangefunc @@ -57,7 +58,13 @@ jobs: - name: Generate and format run: bin/task gen - - name: Run tests + - name: Run short tests + run: bin/task test-short + + - name: Start development environment + run: bin/task env-up-detach + + - name: Run all tests run: bin/task test - name: Fuzz diff --git a/Taskfile.yml b/Taskfile.yml index 3f5c253..86792cf 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -17,11 +17,34 @@ tasks: - go generate -x init: + desc: "Install development tools" deps: [init-tools] cmds: - go mod tidy - go mod verify + env-up-detach: + cmds: + - docker version + - docker compose version + - > + docker compose up --always-recreate-deps --force-recreate --remove-orphans --renew-anon-volumes --timeout=0 --detach + + env-logs: + cmds: + - docker compose logs --follow + + env-up: + desc: "Start development environment" + deps: [env-up-detach] + cmds: + - task: env-logs + + env-down: + desc: "Stop development environment" + cmds: + - docker compose down --remove-orphans --volumes + gen: desc: "Generate and format" cmds: @@ -33,10 +56,17 @@ tasks: cmds: - bin/gofumpt -w . + test-short: + desc: "Run short tests" + cmds: + - go test -short -race ./... + test: - desc: "Run tests" + desc: "Run all tests (requires MONGODB_URI set)" cmds: - - go test ./... + - go test -race ./... + env: + MONGODB_URI: mongodb://localhost:27017/ fuzz: desc: "Fuzz for about 1 minute (with default FUZZ_TIME)" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4aa3e2e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +--- +# This file is used by integration tests. + +services: + mongodb: + image: mongo:latest + ports: + - 27017:27017 diff --git a/wireclient/docker-compose.yml b/wireclient/docker-compose.yml deleted file mode 100644 index ed97d53..0000000 --- a/wireclient/docker-compose.yml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/wireclient/wireclient_test.go b/wireclient/wireclient_test.go index 21b26dd..ea71244 100644 --- a/wireclient/wireclient_test.go +++ b/wireclient/wireclient_test.go @@ -16,8 +16,11 @@ package wireclient import ( "context" + "os" "testing" + "github.com/stretchr/testify/require" + "github.com/FerretDB/wire/internal/util/testutil" ) @@ -26,7 +29,18 @@ func TestConn(t *testing.T) { t.Skip("skipping integration tests for -short") } - // TODO https://github.com/FerretDB/wire/issues/1 + uri := os.Getenv("MONGODB_URI") + require.NotEmpty(t, uri, "MONGODB_URI environment variable must be set; set it or run tests with `go test -short`") + + ctx := context.Background() + + conn, err := Connect(ctx, uri, testutil.Logger(t)) + require.NoError(t, err) + t.Cleanup(func() { + require.NoError(t, conn.Close()) + }) - Connect(context.TODO(), "mongodb://127.0.0.1:27017/", testutil.Logger(t)) + t.Run("SomeTest", func(t *testing.T) { + // TODO https://github.com/FerretDB/wire/issues/1 + }) }