Update rove-server main with tests
This commit is contained in:
parent
1d2087e2b9
commit
97d3583384
3 changed files with 29 additions and 6 deletions
|
@ -14,17 +14,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var ver = flag.Bool("version", false, "Display version number")
|
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 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()
|
flag.Parse()
|
||||||
|
|
||||||
// Print the version if requested
|
// Print the version if requested
|
||||||
if *ver {
|
if *ver {
|
||||||
fmt.Println(version.Version)
|
fmt.Println(version.Version)
|
||||||
os.Exit(0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Initialising version %s...\n", version.Version)
|
fmt.Printf("Initialising version %s...\n", version.Version)
|
||||||
|
@ -34,7 +34,7 @@ func main() {
|
||||||
|
|
||||||
// Create the server data
|
// Create the server data
|
||||||
s := server.NewServer(
|
s := server.NewServer(
|
||||||
server.OptionAddress(*port),
|
server.OptionAddress(*address),
|
||||||
server.OptionPersistentData())
|
server.OptionPersistentData())
|
||||||
|
|
||||||
// Initialise the server
|
// Initialise the server
|
||||||
|
@ -74,3 +74,8 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
InnerMain()
|
||||||
|
}
|
||||||
|
|
18
cmd/rove-server/main_test.go
Normal file
18
cmd/rove-server/main_test.go
Normal 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")
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ go build ./...
|
||||||
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 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
|
# 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
|
Loading…
Add table
Add a link
Reference in a new issue