(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestHTTP(t *testing.T) { |
| 76 | a := assertions.New(t) |
| 77 | |
| 78 | httpAddress, httpsAddress := "0.0.0.0:9185", "0.0.0.0:9186" |
| 79 | baseConfig := component.Config{} |
| 80 | |
| 81 | workingRoutePath := "/ok" |
| 82 | workingRoute := registererFunc(func(s *web.Server) { |
| 83 | s.Router().Path(workingRoutePath).HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 84 | w.WriteHeader(http.StatusOK) |
| 85 | }) |
| 86 | }) |
| 87 | |
| 88 | // HTTP |
| 89 | { |
| 90 | config := baseConfig |
| 91 | config.HTTP.Listen = httpAddress |
| 92 | config.HTTP.ListenTLS = "" |
| 93 | |
| 94 | c, err := component.New(test.GetLogger(t), &config) |
| 95 | a.So(err, should.BeNil) |
| 96 | c.RegisterWeb(workingRoute) |
| 97 | |
| 98 | err = c.Start() |
| 99 | a.So(err, should.BeNil) |
| 100 | |
| 101 | { |
| 102 | // Non-registered path |
| 103 | resp, err := http.Get(fmt.Sprintf("http://%s/not found", httpAddress)) |
| 104 | a.So(err, should.BeNil) |
| 105 | a.So(resp.StatusCode, should.Equal, http.StatusNotFound) |
| 106 | |
| 107 | // Registered path |
| 108 | resp, err = http.Get(fmt.Sprintf("http://%s%s", httpAddress, workingRoutePath)) |
| 109 | a.So(err, should.BeNil) |
| 110 | a.So(resp.StatusCode, should.Equal, http.StatusOK) |
| 111 | } |
| 112 | |
| 113 | c.Close() |
| 114 | } |
| 115 | |
| 116 | // Invalid HTTP port |
| 117 | { |
| 118 | config := baseConfig |
| 119 | config.HTTP.Listen = "0.0.0.0:12391483" |
| 120 | |
| 121 | c, err := component.New(test.GetLogger(t), &config) |
| 122 | a.So(err, should.BeNil) |
| 123 | |
| 124 | err = c.Start() |
| 125 | a.So(err, should.NotBeNil) |
| 126 | } |
| 127 | |
| 128 | // HTTPS |
| 129 | { |
| 130 | config := baseConfig |
| 131 | |
| 132 | config.HTTP.Listen = "" |
nothing calls this directly
no test coverage detected