MCPcopy Create free account
hub / github.com/zalando/skipper / TestRoutingHandlerJsonResponse

Function TestRoutingHandlerJsonResponse

routing/routing_test.go:616–656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

614}
615
616func TestRoutingHandlerJsonResponse(t *testing.T) {
617 dc, _ := testdataclient.NewDoc(`
618 route1: CustomPredicate("custom1") -> "https://route1.example.org";
619 route2: CustomPredicate("custom2") -> "https://route2.example.org";
620 catchAll: * -> "https://route.example.org"`)
621 defer dc.Close()
622
623 cps := []routing.PredicateSpec{&predicate{}, &predicate{}}
624 tr, _ := newTestRoutingWithPredicates(cps, dc)
625 defer tr.close()
626
627 mux := http.NewServeMux()
628 mux.Handle("/", tr.routing)
629 server := httptest.NewServer(mux)
630 defer server.Close()
631
632 req, _ := http.NewRequest("GET", server.URL, nil)
633 req.Header.Set("accept", "application/json")
634 resp, err := http.DefaultClient.Do(req)
635 if err != nil {
636 t.Errorf("unexpected server error: %v", err)
637 }
638 defer resp.Body.Close()
639
640 if got, want := resp.StatusCode, 200; got != want {
641 t.Errorf("status code = %v, want %v", got, want)
642 }
643
644 if got, want := resp.Header.Get("content-type"), "application/json"; got != want {
645 t.Errorf("content type = %v, want %v", got, want)
646 }
647
648 var routes []*eskip.Route
649 if err := json.NewDecoder(resp.Body).Decode(&routes); err != nil {
650 t.Errorf("failed to encode the response body: %v", err)
651 }
652
653 if got, want := len(routes), 3; got != want {
654 t.Errorf("number of routes = %v, want %v", got, want)
655 }
656}
657
658func TestRoutingHandlerFilterInvalidRoutes(t *testing.T) {
659 dc, _ := testdataclient.NewDoc(`

Callers

nothing calls this directly

Calls 8

NewDocFunction · 0.92
CloseMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…