Move server package out into rove-server
This commit is contained in:
		
							parent
							
								
									62d6213c1a
								
							
						
					
					
						commit
						6fb7ee598d
					
				
					 9 changed files with 27 additions and 41 deletions
				
			
		
							
								
								
									
										10
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
					@ -15,8 +15,14 @@ test:
 | 
				
			||||||
	# Run the server and shut it down again to ensure our docker-compose works
 | 
						# 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
 | 
						ROVE_ARGS="--quit 1" docker-compose up --build --exit-code-from=rove-server --abort-on-container-exit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# Run tests with coverage
 | 
						# Run the server and shut it down again to ensure our docker-compose works
 | 
				
			||||||
	go test -v ./... -cover -coverprofile=/tmp/c.out -count 1
 | 
						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
 | 
						# 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package main
 | 
					package internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,6 @@ import (
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
	"github.com/mdiluz/rove/pkg/game"
 | 
						"github.com/mdiluz/rove/pkg/game"
 | 
				
			||||||
	"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"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +15,7 @@ import (
 | 
				
			||||||
var serv rove.Server
 | 
					var serv rove.Server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestMain(m *testing.M) {
 | 
					func TestMain(m *testing.M) {
 | 
				
			||||||
	s := server.NewServer()
 | 
						s := NewServer()
 | 
				
			||||||
	if err := s.Initialise(true); err != nil {
 | 
						if err := s.Initialise(true); err != nil {
 | 
				
			||||||
		fmt.Println(err)
 | 
							fmt.Println(err)
 | 
				
			||||||
		os.Exit(1)
 | 
							os.Exit(1)
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package server
 | 
					package internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package server
 | 
					package internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package server
 | 
					package internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
package server
 | 
					package internal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
| 
						 | 
					@ -8,8 +8,8 @@ import (
 | 
				
			||||||
	"syscall"
 | 
						"syscall"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/mdiluz/rove/cmd/rove-server/internal"
 | 
				
			||||||
	"github.com/mdiluz/rove/pkg/persistence"
 | 
						"github.com/mdiluz/rove/pkg/persistence"
 | 
				
			||||||
	"github.com/mdiluz/rove/pkg/server"
 | 
					 | 
				
			||||||
	"github.com/mdiluz/rove/pkg/version"
 | 
						"github.com/mdiluz/rove/pkg/version"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,10 +34,10 @@ func InnerMain() {
 | 
				
			||||||
	persistence.SetPath(*data)
 | 
						persistence.SetPath(*data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Create the server data
 | 
						// Create the server data
 | 
				
			||||||
	s := server.NewServer(
 | 
						s := internal.NewServer(
 | 
				
			||||||
		server.OptionAddress(*address),
 | 
							internal.OptionAddress(*address),
 | 
				
			||||||
		server.OptionPersistentData(),
 | 
							internal.OptionPersistentData(),
 | 
				
			||||||
		server.OptionTick(*tick))
 | 
							internal.OptionTick(*tick))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Initialise the server
 | 
						// Initialise the server
 | 
				
			||||||
	if err := s.Initialise(true); err != nil {
 | 
						if err := s.Initialise(true); err != nil {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,40 +1,18 @@
 | 
				
			||||||
 | 
					// +build integration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"flag"
 | 
						"flag"
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"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"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var address string
 | 
					var address = "localhost:80"
 | 
				
			||||||
 | 
					 | 
				
			||||||
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)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -294,8 +294,11 @@ func (w *World) Enqueue(rover uuid.UUID, commands ...Command) error {
 | 
				
			||||||
	defer w.cmdMutex.Unlock()
 | 
						defer w.cmdMutex.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Append the commands to the incoming set
 | 
						// Append the commands to the incoming set
 | 
				
			||||||
	cmds := w.Incoming[rover]
 | 
						if cmds, ok := w.Incoming[rover]; ok {
 | 
				
			||||||
		w.Incoming[rover] = append(cmds, commands...)
 | 
							w.Incoming[rover] = append(cmds, commands...)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							w.Incoming[rover] = commands
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue