Add better test output
This commit is contained in:
		
							parent
							
								
									6531a2f107
								
							
						
					
					
						commit
						c7ac15a287
					
				
					 1 changed files with 16 additions and 9 deletions
				
			
		|  | @ -4,7 +4,6 @@ import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
| 	"os" | 	"os" | ||||||
|  | @ -71,9 +70,11 @@ func main() { | ||||||
| 
 | 
 | ||||||
| 	server := httptest.NewServer(router) | 	server := httptest.NewServer(router) | ||||||
| 
 | 
 | ||||||
| 	exec.Command("chromium", "--headless", "--disable-gpu", server.URL).Run() | 	testBrowser("chrome", "--headless", "--disable-gpu", server.URL) | ||||||
| 	// TODO: Fix closing FF | 	testBrowser("chromium", "--headless", "--disable-gpu", server.URL) | ||||||
| 	exec.Command("firefox", "-headless", server.URL).Run() | 
 | ||||||
|  | 	// Firefox is being annoying, enable if you like | ||||||
|  | 	// testBrowser("firefox", "-headless", server.URL) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Person ... | // 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) { | func postTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||||||
| 	body, _ := ioutil.ReadAll(r.Body) |  | ||||||
| 
 |  | ||||||
| 	var p []*Person | 	var p []*Person | ||||||
| 
 | 
 | ||||||
| 	err := json.Unmarshal(body, &p) | 	body := json.NewDecoder(r.Body) | ||||||
|  | 	err := body.Decode(&p) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Println(err) | 		fmt.Println(color.RedString(err.Error())) | ||||||
| 		fmt.Println("Person could not be decoded") |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for k := range p { | 	for k := range p { | ||||||
|  | @ -116,6 +115,14 @@ func postTest(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | ||||||
| 	tw.Flush() | 	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) { | func isEq(p1, p2 Person) { | ||||||
| 	assert(p1.Name, p2.Name, "Name") | 	assert(p1.Name, p2.Name, "Name") | ||||||
| 	assert(p1.Surname, p2.Surname, "Surname") | 	assert(p1.Surname, p2.Surname, "Surname") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue