(t *testing.T)
| 798 | } |
| 799 | |
| 800 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…