github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/serve_test.go (about) 1 package alfred 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 ) 8 9 func TestServeComponent(t *testing.T) { 10 11 /* I think travis-ci.org isn't allowing ports anymore? 12 Needs investgating ... and this test needs fixing if that's the case. 13 For now, lets limit it to just my username /cringe 14 */ 15 16 if evaluate("whoami", "./") != "kcmerrill" { 17 return 18 } 19 20 tasks := make(map[string]Task) 21 tasks["http.serve"] = Task{ 22 Serve: "8088", 23 } 24 context := InitialContext([]string{}) 25 context.Text.DisableFormatting = true 26 27 go serve(tasks["http.serve"], context, tasks) 28 response, err := http.Get("http://localhost:8088/serve_test.go") 29 if err != nil { 30 fmt.Println(err.Error()) 31 t.Fatalf("Expected a proper 200 response from localhost") 32 } 33 if response.StatusCode != 200 { 34 t.Fatalf("Status code 200 expected") 35 } 36 }