From 8dca98c6b33742c0fd9e014b5d1a87a1e0a52199 Mon Sep 17 00:00:00 2001 From: Umputun Date: Fri, 16 Apr 2021 11:10:07 -0500 Subject: [PATCH] don't resort rules for file provider inside the server #37 --- app/discovery/provider/file.go | 5 +---- app/discovery/provider/file_test.go | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/discovery/provider/file.go b/app/discovery/provider/file.go index 5701b7c..35706e6 100644 --- a/app/discovery/provider/file.go +++ b/app/discovery/provider/file.go @@ -110,10 +110,7 @@ func (d *File) List() (res []discovery.URLMapper, err error) { } } sort.Slice(res, func(i, j int) bool { - if res[i].Server == res[j].Server { - return res[i].SrcMatch.String() < res[j].SrcMatch.String() - } - return res[i].Server < res[j].Server + return len(res[i].Server) > len(res[j].Server) }) err = fh.Close() diff --git a/app/discovery/provider/file_test.go b/app/discovery/provider/file_test.go index e9b54fd..502e775 100644 --- a/app/discovery/provider/file_test.go +++ b/app/discovery/provider/file_test.go @@ -107,23 +107,24 @@ func TestFile_List(t *testing.T) { t.Logf("%+v", res) assert.Equal(t, 4, len(res)) - assert.Equal(t, "/api/svc3/xyz", res[0].SrcMatch.String()) - assert.Equal(t, "http://127.0.0.3:8080/blah3/xyz", res[0].Dst) - assert.Equal(t, "http://127.0.0.3:8080/ping", res[0].PingURL) - assert.Equal(t, "*", res[0].Server) + assert.Equal(t, "^/api/svc2/(.*)", res[0].SrcMatch.String()) + assert.Equal(t, "http://127.0.0.2:8080/blah2/$1/abc", res[0].Dst) + assert.Equal(t, "", res[0].PingURL) + assert.Equal(t, "srv.example.com", res[0].Server) - assert.Equal(t, "/web/", res[1].SrcMatch.String()) - assert.Equal(t, "/var/web", res[1].Dst) + assert.Equal(t, "^/api/svc1/(.*)", res[1].SrcMatch.String()) + assert.Equal(t, "http://127.0.0.1:8080/blah1/$1", res[1].Dst) assert.Equal(t, "", res[1].PingURL) assert.Equal(t, "*", res[1].Server) - assert.Equal(t, "^/api/svc1/(.*)", res[2].SrcMatch.String()) - assert.Equal(t, "http://127.0.0.1:8080/blah1/$1", res[2].Dst) - assert.Equal(t, "", res[2].PingURL) + assert.Equal(t, "/api/svc3/xyz", res[2].SrcMatch.String()) + assert.Equal(t, "http://127.0.0.3:8080/blah3/xyz", res[2].Dst) + assert.Equal(t, "http://127.0.0.3:8080/ping", res[2].PingURL) assert.Equal(t, "*", res[2].Server) - assert.Equal(t, "^/api/svc2/(.*)", res[3].SrcMatch.String()) - assert.Equal(t, "http://127.0.0.2:8080/blah2/$1/abc", res[3].Dst) + assert.Equal(t, "/web/", res[3].SrcMatch.String()) + assert.Equal(t, "/var/web", res[3].Dst) assert.Equal(t, "", res[3].PingURL) - assert.Equal(t, "srv.example.com", res[3].Server) + assert.Equal(t, "*", res[3].Server) + }