Move server package out into rove-server

This commit is contained in:
Marc Di Luzio 2020-06-10 17:39:42 +01:00
parent 62d6213c1a
commit 6fb7ee598d
9 changed files with 27 additions and 41 deletions

View file

@ -15,8 +15,14 @@ test:
# Run the server and shut it down again to ensure our docker-compose works
ROVE_ARGS="--quit 1" docker-compose up --build --exit-code-from=rove-server --abort-on-container-exit
# Run tests with coverage
go test -v ./... -cover -coverprofile=/tmp/c.out -count 1
# Run the server and shut it down again to ensure our docker-compose works
docker-compose up -d
# Run tests with coverage and integration tags
go test -v ./... --tags=integration -cover -coverprofile=/tmp/c.out -count 1
#
docker-compose down
# Convert the coverage data to html
go tool cover -html=/tmp/c.out -o /tmp/coverage.html

View file

@ -1,4 +1,4 @@
package main
package internal
import (
"fmt"
@ -8,7 +8,6 @@ import (
"github.com/google/uuid"
"github.com/mdiluz/rove/pkg/game"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/server"
"github.com/stretchr/testify/assert"
)
@ -16,7 +15,7 @@ import (
var serv rove.Server
func TestMain(m *testing.M) {
s := server.NewServer()
s := NewServer()
if err := s.Initialise(true); err != nil {
fmt.Println(err)
os.Exit(1)

View file

@ -1,4 +1,4 @@
package server
package internal
import (
"encoding/json"

View file

@ -1,4 +1,4 @@
package server
package internal
import (
"bytes"

View file

@ -1,4 +1,4 @@
package server
package internal
import (
"context"

View file

@ -1,4 +1,4 @@
package server
package internal
import (
"testing"

View file

@ -8,8 +8,8 @@ import (
"syscall"
"time"
"github.com/mdiluz/rove/cmd/rove-server/internal"
"github.com/mdiluz/rove/pkg/persistence"
"github.com/mdiluz/rove/pkg/server"
"github.com/mdiluz/rove/pkg/version"
)
@ -34,10 +34,10 @@ func InnerMain() {
persistence.SetPath(*data)
// Create the server data
s := server.NewServer(
server.OptionAddress(*address),
server.OptionPersistentData(),
server.OptionTick(*tick))
s := internal.NewServer(
internal.OptionAddress(*address),
internal.OptionPersistentData(),
internal.OptionTick(*tick))
// Initialise the server
if err := s.Initialise(true); err != nil {

View file

@ -1,40 +1,18 @@
// +build integration
package main
import (
"flag"
"fmt"
"os"
"path"
"testing"
"github.com/google/uuid"
"github.com/mdiluz/rove/pkg/server"
"github.com/stretchr/testify/assert"
)
var address string
func TestMain(m *testing.M) {
s := server.NewServer()
if err := s.Initialise(true); err != nil {
fmt.Println(err)
os.Exit(1)
}
address = s.Addr()
go s.Run()
fmt.Printf("Test server hosted on %s", address)
code := m.Run()
if err := s.StopAndClose(); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(code)
}
var address = "localhost:80"
func Test_InnerMain(t *testing.T) {
// Set up the flags to act locally and use a temporary file

View file

@ -294,8 +294,11 @@ func (w *World) Enqueue(rover uuid.UUID, commands ...Command) error {
defer w.cmdMutex.Unlock()
// Append the commands to the incoming set
cmds := w.Incoming[rover]
if cmds, ok := w.Incoming[rover]; ok {
w.Incoming[rover] = append(cmds, commands...)
} else {
w.Incoming[rover] = commands
}
return nil
}