Update rove-server main with tests

This commit is contained in:
Marc Di Luzio 2020-06-06 12:13:54 +01:00
parent 1d2087e2b9
commit 97d3583384
3 changed files with 29 additions and 6 deletions

View file

@ -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()
}

View file

@ -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")
}