Add better test output

This commit is contained in:
Crow Crowcrow 2017-08-27 14:22:06 +02:00
parent 6531a2f107
commit c7ac15a287
1 changed files with 16 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
@ -71,9 +70,11 @@ func main() {
server := httptest.NewServer(router)
exec.Command("chromium", "--headless", "--disable-gpu", server.URL).Run()
// TODO: Fix closing FF
exec.Command("firefox", "-headless", server.URL).Run()
testBrowser("chrome", "--headless", "--disable-gpu", server.URL)
testBrowser("chromium", "--headless", "--disable-gpu", server.URL)
// Firefox is being annoying, enable if you like
// testBrowser("firefox", "-headless", server.URL)
}
// Person ...
@ -97,14 +98,12 @@ func getTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
}
func postTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
body, _ := ioutil.ReadAll(r.Body)
var p []*Person
err := json.Unmarshal(body, &p)
body := json.NewDecoder(r.Body)
err := body.Decode(&p)
if err != nil {
fmt.Println(err)
fmt.Println("Person could not be decoded")
fmt.Println(color.RedString(err.Error()))
}
for k := range p {
@ -116,6 +115,14 @@ func postTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
tw.Flush()
}
func testBrowser(command string, flags ...string) {
fmt.Println("\nTesting", color.RedString(command))
err := exec.Command(command, flags...).Run()
if err != nil {
fmt.Println(color.RedString(err.Error()))
}
}
func isEq(p1, p2 Person) {
assert(p1.Name, p2.Name, "Name")
assert(p1.Surname, p2.Surname, "Surname")