to run this test, set `-args listener` for the test command
(t *testing.T)
| 255 | |
| 256 | // to run this test, set `-args listener` for the test command |
| 257 | func TestHTTPSServer(t *testing.T) { |
| 258 | // TODO: figure why sometimes cannot connect |
| 259 | if !testListener() { |
| 260 | t.Log("Failed to get testListener skip test TestHTTPSServer") |
| 261 | t.Skip() |
| 262 | } |
| 263 | |
| 264 | MuFindAddress.Lock() |
| 265 | a := FindAddress(t) |
| 266 | i := FindAddress(t) |
| 267 | |
| 268 | o := Options{ |
| 269 | Address: a, |
| 270 | InsecureAddress: i, |
| 271 | CertPathTLS: "fixtures/test.crt", |
| 272 | KeyPathTLS: "fixtures/test.key", |
| 273 | } |
| 274 | |
| 275 | rt := routing.New(routing.Options{ |
| 276 | FilterRegistry: builtin.MakeRegistry(), |
| 277 | DataClients: []routing.DataClient{}}) |
| 278 | defer rt.Close() |
| 279 | |
| 280 | proxy := proxy.WithParams(proxy.Params{ |
| 281 | Routing: rt, |
| 282 | Flags: proxy.Flags(proxy.OptionsNone), |
| 283 | Metrics: &metricstest.MockMetrics{}, |
| 284 | }) |
| 285 | defer proxy.Close() |
| 286 | go listenAndServe(proxy, &o) |
| 287 | |
| 288 | r, err := waitConnGet("https://" + o.Address) |
| 289 | if r != nil { |
| 290 | defer r.Body.Close() |
| 291 | } |
| 292 | if err != nil { |
| 293 | t.Fatalf("Cannot connect to the local server for testing: %s ", err.Error()) |
| 294 | } |
| 295 | if r.StatusCode != 404 { |
| 296 | t.Fatalf("Status code should be 404, instead got: %d\n", r.StatusCode) |
| 297 | } |
| 298 | _, err = io.ReadAll(r.Body) |
| 299 | if err != nil { |
| 300 | t.Fatalf("Failed to stream response body: %v", err) |
| 301 | } |
| 302 | |
| 303 | r, err = waitConnGet("http://" + o.InsecureAddress) |
| 304 | MuFindAddress.Unlock() |
| 305 | if r != nil { |
| 306 | defer r.Body.Close() |
| 307 | } |
| 308 | if err != nil { |
| 309 | t.Fatalf("Cannot connect to the local server for testing: %s ", err.Error()) |
| 310 | } |
| 311 | if r.StatusCode != 404 { |
| 312 | t.Fatalf("Status code should be 404, instead got: %d\n", r.StatusCode) |
| 313 | } |
| 314 | _, err = io.ReadAll(r.Body) |
nothing calls this directly
no test coverage detected
searching dependent graphs…