From 2b492d840ad824020f6cfd8651c2093895ed6b9f Mon Sep 17 00:00:00 2001 From: Umputun Date: Sat, 17 Apr 2021 02:35:23 -0500 Subject: [PATCH] fix tests --- app/discovery/discovery.go | 2 +- app/discovery/discovery_test.go | 10 +++++++--- app/discovery/provider/docker_test.go | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/discovery/discovery.go b/app/discovery/discovery.go index 53a3c93..b0433ab 100644 --- a/app/discovery/discovery.go +++ b/app/discovery/discovery.go @@ -136,7 +136,7 @@ func (s *Service) Match(srv, src string) (string, MatchType, bool) { return dest, m.MatchType, true } case MTStatic: - if src == m.AssetsWebRoot || strings.HasSuffix(src, m.AssetsWebRoot+"/") { + if src == m.AssetsWebRoot || strings.HasPrefix(src, m.AssetsWebRoot+"/") { return m.AssetsWebRoot + ":" + m.AssetsLocation, MTStatic, true } } diff --git a/app/discovery/discovery_test.go b/app/discovery/discovery_test.go index 66b63fe..782a82e 100644 --- a/app/discovery/discovery_test.go +++ b/app/discovery/discovery_test.go @@ -81,8 +81,10 @@ func TestService_Match(t *testing.T) { ListFunc: func() ([]URLMapper, error) { return []URLMapper{ {SrcMatch: *regexp.MustCompile("/api/svc3/xyz"), Dst: "http://127.0.0.3:8080/blah3/xyz", ProviderID: PIDocker}, - {SrcMatch: *regexp.MustCompile("/web"), Dst: "/var/web", ProviderID: PIDocker, MatchType: MTStatic}, - {SrcMatch: *regexp.MustCompile("/www/"), Dst: "/var/web", ProviderID: PIDocker, MatchType: MTStatic}, + {SrcMatch: *regexp.MustCompile("/web"), Dst: "/var/web", ProviderID: PIDocker, MatchType: MTStatic, + AssetsWebRoot: "/web", AssetsLocation: "/var/web"}, + {SrcMatch: *regexp.MustCompile("/www/"), Dst: "/var/web", ProviderID: PIDocker, MatchType: MTStatic, + AssetsWebRoot: "/www", AssetsLocation: "/var/web"}, }, nil }, } @@ -101,6 +103,7 @@ func TestService_Match(t *testing.T) { mt MatchType ok bool }{ + {"example.com", "/api/svc3/xyz/something", "http://127.0.0.3:8080/blah3/xyz/something", MTProxy, true}, {"example.com", "/api/svc3/xyz", "http://127.0.0.3:8080/blah3/xyz", MTProxy, true}, {"abc.example.com", "/api/svc1/1234", "http://127.0.0.1:8080/blah1/1234", MTProxy, true}, @@ -109,8 +112,9 @@ func TestService_Match(t *testing.T) { {"m1.example.com", "/api/svc2/1234", "/api/svc2/1234", MTProxy, false}, {"m1.example.com", "/web/index.html", "/web:/var/web/", MTStatic, true}, {"m1.example.com", "/web/", "/web:/var/web/", MTStatic, true}, - {"m1.example.com", "/www", "/www:/var/web/", MTStatic, true}, {"m1.example.com", "/www/something", "/www:/var/web/", MTStatic, true}, + {"m1.example.com", "/www/", "/www:/var/web/", MTStatic, true}, + {"m1.example.com", "/www", "/www:/var/web/", MTStatic, true}, } for i, tt := range tbl { diff --git a/app/discovery/provider/docker_test.go b/app/discovery/provider/docker_test.go index 0041bbf..7da51cb 100644 --- a/app/discovery/provider/docker_test.go +++ b/app/discovery/provider/docker_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/umputun/reproxy/app/discovery" ) @@ -173,7 +174,7 @@ func TestDocker_refresh(t *testing.T) { func TestDockerClient(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, "/v1.41/containers/json", r.URL.Path) + require.Equal(t, "/containers/json", r.URL.Path) // obtained using curl --unix-socket /var/run/docker.sock http://localhost/v1.41/containers/json resp, err := ioutil.ReadFile("testdata/containers.json")