From 7004aa83f2a68735e4c12bf1b8291659bfa67054 Mon Sep 17 00:00:00 2001 From: Umputun Date: Tue, 6 Apr 2021 23:59:23 -0500 Subject: [PATCH] fix flaky test --- app/discovery/provider/file.go | 7 +++++++ app/discovery/provider/file_test.go | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/discovery/provider/file.go b/app/discovery/provider/file.go index 6268671..6f61061 100644 --- a/app/discovery/provider/file.go +++ b/app/discovery/provider/file.go @@ -4,6 +4,7 @@ import ( "context" "os" "regexp" + "sort" "time" log "github.com/go-pkgz/lgr" @@ -95,6 +96,12 @@ func (d *File) List() (res []discovery.UrlMapper, err error) { res = append(res, mapper) } } + 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 res, nil } diff --git a/app/discovery/provider/file_test.go b/app/discovery/provider/file_test.go index ddccad6..093fcf2 100644 --- a/app/discovery/provider/file_test.go +++ b/app/discovery/provider/file_test.go @@ -58,10 +58,19 @@ func TestFile_List(t *testing.T) { require.NoError(t, err) t.Logf("%+v", res) assert.Equal(t, 3, len(res)) - assert.Equal(t, "^/api/svc1/(.*)", res[0].SrcMatch.String()) - assert.Equal(t, "http://127.0.0.3:8080/blah3/xyz", res[1].Dst) - assert.Equal(t, "http://127.0.0.3:8080/ping", res[1].PingURL) + + 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/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/svc2/(.*)", res[2].SrcMatch.String()) assert.Equal(t, "http://127.0.0.2:8080/blah2/$1/abc", res[2].Dst) assert.Equal(t, "", res[2].PingURL) - + assert.Equal(t, "srv.example.com", res[2].Server) }