fix tests

This commit is contained in:
Umputun 2021-04-17 02:35:23 -05:00
parent ee4f8919e1
commit 2b492d840a
3 changed files with 10 additions and 5 deletions

View File

@ -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
}
}

View File

@ -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 {

View File

@ -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")