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

Function TestUpdateFailsRecovers

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

Source from the content-addressed store, hash-verified

798}
799
800func TestUpdateFailsRecovers(t *testing.T) {
801 l := loggingtest.New()
802 defer l.Close()
803
804 dc, err := testdataclient.NewDoc(`
805 foo: Path("/foo") -> setPath("/") -> "https://foo.example.org";
806 bar: Path("/bar") -> setPath("/") -> "https://bar.example.org";
807 baz: Path("/baz") -> setPath("/") -> "https://baz.example.org";
808 `)
809 if err != nil {
810 t.Fatal(err)
811 }
812 defer dc.Close()
813
814 rt := routing.New(routing.Options{
815 FilterRegistry: builtin.MakeRegistry(),
816 DataClients: []routing.DataClient{dc},
817 PollTimeout: 12 * time.Millisecond,
818 Log: l,
819 })
820 defer rt.Close()
821
822 check := func(id, path, backend string, match bool) {
823 if t.Failed() {
824 return
825 }
826
827 if r, _ := rt.Route(&http.Request{URL: &url.URL{Path: path}}); r == nil && match {
828 t.Error("route not found:", id)
829 } else if r == nil && !match {
830 return
831 } else if !match {
832 t.Error("unexpected route found:", id, path)
833 } else if r.Id != id || r.Backend != backend {
834 t.Error("invalid route matched")
835 t.Log("got: ", r.Id, r.Backend)
836 t.Log("expected:", id, backend)
837 }
838 }
839
840 if err := l.WaitFor("route settings applied", 120*time.Millisecond); err != nil {
841 t.Fatal(err)
842 }
843
844 check("foo", "/foo", "https://foo.example.org", true)
845 check("bar", "/bar", "https://bar.example.org", true)
846 check("baz", "/baz", "https://baz.example.org", true)
847
848 l.Reset()
849 dc.FailNext()
850
851 if err := dc.UpdateDoc(`
852 foo: Path("/foo") -> setPath("/") -> "https://foo.example.org";
853 baz: Path("/baz") -> setPath("/") -> "https://baz-new.example.org";
854 `, []string{"bar"}); err != nil {
855 t.Fatal(err)
856 }
857

Callers

nothing calls this directly

Calls 13

NewFunction · 0.92
NewDocFunction · 0.92
NewFunction · 0.92
MakeRegistryFunction · 0.92
checkStruct · 0.85
RouteMethod · 0.80
LogMethod · 0.80
FailNextMethod · 0.80
UpdateDocMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…