diff --git a/test-data/sample-root.pem b/.testdata/sample-root.pem similarity index 100% rename from test-data/sample-root.pem rename to .testdata/sample-root.pem diff --git a/test-data/test-img.png b/.testdata/test-img.png similarity index 100% rename from test-data/test-img.png rename to .testdata/test-img.png diff --git a/test-data/text-file.txt b/.testdata/text-file.txt similarity index 100% rename from test-data/text-file.txt rename to .testdata/text-file.txt diff --git a/BUILD.bazel b/BUILD.bazel index 19030766..698c326c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -27,7 +27,7 @@ go_test( ["*_test.go"], exclude = ["example_test.go"], ), - data = glob(["test-data/*"]), + data = glob([".testdata/*"]), embed = [":go_default_library"], importpath = "gopkg.in/resty.v1", deps = [ diff --git a/middleware.go b/middleware.go index 7b7ceb72..801e8647 100644 --- a/middleware.go +++ b/middleware.go @@ -28,12 +28,12 @@ func parseRequestURL(c *Client, r *Request) error { // GitHub #103 Path Params if len(r.pathParams) > 0 { for p, v := range r.pathParams { - r.URL = strings.Replace(r.URL, "{"+p+"}", v, -1) + r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1) } } if len(c.pathParams) > 0 { for p, v := range c.pathParams { - r.URL = strings.Replace(r.URL, "{"+p+"}", v, -1) + r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1) } } diff --git a/request_test.go b/request_test.go index bf51f51a..c4dcfb4a 100644 --- a/request_test.go +++ b/request_test.go @@ -535,7 +535,7 @@ func TestFormDataDisableWarn(t *testing.T) { func TestMultiPartUploadFile(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") basePath := getTestDataPath() @@ -554,7 +554,7 @@ func TestMultiPartUploadFile(t *testing.T) { func TestMultiPartUploadFileError(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") basePath := getTestDataPath() @@ -576,7 +576,7 @@ func TestMultiPartUploadFileError(t *testing.T) { func TestMultiPartUploadFiles(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") basePath := getTestDataPath() @@ -596,7 +596,7 @@ func TestMultiPartUploadFiles(t *testing.T) { func TestMultiPartIoReaderFiles(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") basePath := getTestDataPath() profileImgBytes, _ := ioutil.ReadFile(filepath.Join(basePath, "test-img.png")) @@ -627,7 +627,7 @@ func TestMultiPartIoReaderFiles(t *testing.T) { func TestMultiPartUploadFileNotOnGetOrDelete(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") basePath := getTestDataPath() @@ -647,7 +647,7 @@ func TestMultiPartUploadFileNotOnGetOrDelete(t *testing.T) { func TestMultiPartMultipartField(t *testing.T) { ts := createFormPostServer(t) defer ts.Close() - defer cleanupFiles("test-data/upload") + defer cleanupFiles(".testdata/upload") jsonBytes := []byte(`{"input": {"name": "Uploaded document", "_filename" : ["file.txt"]}}`) @@ -1103,7 +1103,7 @@ func TestSetQueryStringTypical(t *testing.T) { func TestOutputFileWithBaseDirAndRelativePath(t *testing.T) { ts := createGetServer(t) defer ts.Close() - defer cleanupFiles("test-data/dir-sample") + defer cleanupFiles(".testdata/dir-sample") DefaultClient = dc() SetRedirectPolicy(FlexibleRedirectPolicy(10)) @@ -1129,7 +1129,7 @@ func TestOutputFileWithBaseDirError(t *testing.T) { func TestOutputPathDirNotExists(t *testing.T) { ts := createGetServer(t) defer ts.Close() - defer cleanupFiles(filepath.Join("test-data", "not-exists-dir")) + defer cleanupFiles(filepath.Join(".testdata", "not-exists-dir")) DefaultClient = dc() SetRedirectPolicy(FlexibleRedirectPolicy(10)) @@ -1146,7 +1146,7 @@ func TestOutputPathDirNotExists(t *testing.T) { func TestOutputFileAbsPath(t *testing.T) { ts := createGetServer(t) defer ts.Close() - defer cleanupFiles(filepath.Join("test-data", "go-resty")) + defer cleanupFiles(filepath.Join(".testdata", "go-resty")) _, err := dcr(). SetOutput(filepath.Join(getTestDataPath(), "go-resty", "test-img-success-2.png")). @@ -1415,7 +1415,7 @@ func TestPathParamURLInput(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, true, strings.Contains(resp.String(), "TestPathParamURLInput: text response")) - assertEqual(t, true, strings.Contains(resp.String(), "/v1/users/sample@sample.com/100002/https://example.com")) + assertEqual(t, true, strings.Contains(resp.String(), "/v1/users/sample@sample.com/100002/https:%2F%2Fexample.com")) logResponse(t, resp) } diff --git a/resty_test.go b/resty_test.go index 8b931e54..198b579a 100644 --- a/resty_test.go +++ b/resty_test.go @@ -30,7 +30,7 @@ import ( func getTestDataPath() string { pwd, _ := os.Getwd() - return filepath.Join(pwd, "test-data") + return filepath.Join(pwd, ".testdata") } func createGetServer(t *testing.T) *httptest.Server {