De-integration the cmd/rove tests as well and massively simplify the tests output

This commit is contained in:
Marc Di Luzio 2020-06-06 00:47:48 +01:00
parent 79c07f359b
commit 3bfbe38837
5 changed files with 23 additions and 37 deletions

View file

@ -1,11 +0,0 @@
FROM golang:latest
LABEL maintainer="Marc Di Luzio <marc.diluzio@gmail.com>"
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o rove -ldflags="-X 'github.com/mdiluz/rove/pkg/version.Version=$(git describe --always --long --dirty --tags)'" cmd/rove/main.go
CMD [ "./rove" ]

View file

@ -1,5 +1,3 @@
// +build integration
package main package main
import ( import (
@ -9,9 +7,22 @@ import (
"testing" "testing"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/mdiluz/rove/pkg/server"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestMain(m *testing.M) {
s := server.NewServer(server.OptionPort(8080))
s.Initialise()
go s.Run()
code := m.Run()
s.Close()
os.Exit(code)
}
func Test_InnerMain(t *testing.T) { func Test_InnerMain(t *testing.T) {
// Set up the flags to act locally and use a temporary file // Set up the flags to act locally and use a temporary file
flag.Set("data", path.Join(os.TempDir(), uuid.New().String())) flag.Set("data", path.Join(os.TempDir(), uuid.New().String()))
@ -20,7 +31,7 @@ func Test_InnerMain(t *testing.T) {
assert.Error(t, InnerMain("status")) assert.Error(t, InnerMain("status"))
// Now set the host // Now set the host
flag.Set("host", "localhost:80") flag.Set("host", "localhost:8080")
// No error now as we have a host // No error now as we have a host
assert.NoError(t, InnerMain("status")) assert.NoError(t, InnerMain("status"))

View file

@ -1,11 +0,0 @@
version: '3'
services:
rove-server:
build:
context: .
dockerfile: cmd/rove-server/Dockerfile
image: rove-server:latest
ports:
- "80:80"
command: ./rove-server --port 80

View file

@ -1,4 +1,4 @@
package integration package server
import ( import (
"os" "os"
@ -6,14 +6,13 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/mdiluz/rove/pkg/rove" "github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/server"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var serv rove.Server = "localhost:8080" var serv rove.Server = "localhost:8080"
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
s := server.NewServer(server.OptionPort(8080)) s := NewServer(OptionPort(8080))
s.Initialise() s.Initialise()
go s.Run() go s.Run()

View file

@ -4,18 +4,16 @@ cd "$(dirname "$0")"
cd .. cd ..
set -x set -x
# Check that the cmdline client builds # Check we can build everything
docker build -f "cmd/rove/Dockerfile" .
# Build and start rove-server
docker-compose -f docker-compose-test.yml up --detach --build
# Run tests, including integration tests
go mod download go mod download
go test -v ./... -tags integration -cover -coverprofile=/tmp/c.out go build ./...
# Take down the service # Run the server and shut it down again to ensure our docker-compose works
docker-compose up --detach --build
docker-compose down docker-compose down
# Run tests with coverage
go test -v ./... -cover -coverprofile=/tmp/c.out
# Convert the coverage data to html # Convert the coverage data to html
go tool cover -html=/tmp/c.out -o /tmp/coverage.html go tool cover -html=/tmp/c.out -o /tmp/coverage.html