From 97d35833849da2fe75306c05059c071d3fb51af5 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 6 Jun 2020 12:13:54 +0100 Subject: [PATCH] Update rove-server main with tests --- cmd/rove-server/main.go | 15 ++++++++++----- cmd/rove-server/main_test.go | 18 ++++++++++++++++++ script/test.sh | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 cmd/rove-server/main_test.go diff --git a/cmd/rove-server/main.go b/cmd/rove-server/main.go index e3042ae..fc9000b 100644 --- a/cmd/rove-server/main.go +++ b/cmd/rove-server/main.go @@ -14,17 +14,17 @@ import ( ) var ver = flag.Bool("version", false, "Display version number") -var port = flag.String("address", ":8080", "The address to host on") -var data = flag.String("data", os.TempDir(), "Directory to store persistant data") var quit = flag.Int("quit", 0, "Quit after n seconds, useful for testing") +var address = flag.String("address", "", "The address to host on, automatically selected if empty") +var data = flag.String("data", "", "Directory to store persistant data, no storage if empty") -func main() { +func InnerMain() { flag.Parse() // Print the version if requested if *ver { fmt.Println(version.Version) - os.Exit(0) + return } fmt.Printf("Initialising version %s...\n", version.Version) @@ -34,7 +34,7 @@ func main() { // Create the server data s := server.NewServer( - server.OptionAddress(*port), + server.OptionAddress(*address), server.OptionPersistentData()) // Initialise the server @@ -74,3 +74,8 @@ func main() { panic(err) } } + +func main() { + flag.Parse() + InnerMain() +} diff --git a/cmd/rove-server/main_test.go b/cmd/rove-server/main_test.go new file mode 100644 index 0000000..64aa62c --- /dev/null +++ b/cmd/rove-server/main_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "flag" + "testing" +) + +func Test_InnerMain_Version(t *testing.T) { + flag.Set("version", "1") + InnerMain() + flag.Set("version", "0") +} + +func Test_InnerMain_Quit(t *testing.T) { + flag.Set("quit", "1") + InnerMain() + flag.Set("quit", "0") +} diff --git a/script/test.sh b/script/test.sh index a0ffa6a..67acbe3 100755 --- a/script/test.sh +++ b/script/test.sh @@ -12,7 +12,7 @@ go build ./... 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 +go test -v ./... -cover -coverprofile=/tmp/c.out -count 1 # Convert the coverage data to html go tool cover -html=/tmp/c.out -o /tmp/coverage.html \ No newline at end of file