mirror of
https://github.com/kemko/reproxy.git
synced 2026-01-01 15:55:49 +03:00
fix flaky test
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user