Skip to content

Commit

Permalink
Run integration tests on CI (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Jul 31, 2024
1 parent 64acaca commit 0d5623f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
34 changes: 32 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)"
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# This file is used by integration tests.

services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
1 change: 0 additions & 1 deletion wireclient/docker-compose.yml

This file was deleted.

18 changes: 16 additions & 2 deletions wireclient/wireclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ package wireclient

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/FerretDB/wire/internal/util/testutil"
)

Expand All @@ -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
})
}

0 comments on commit 0d5623f

Please sign in to comment.