Skip to content

Commit

Permalink
fix: BaseURL inconsistency (#51) #patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Eun authored Mar 4, 2021
1 parent baf30e0 commit 0ee4d6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 19 additions & 0 deletions hit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,25 @@ func TestBaseURL(t *testing.T) {
)
}

func TestBaseURLTemplate(t *testing.T) {
// this test should ensure that the baseurl is the same for the two test runs
mux := http.NewServeMux()
mux.HandleFunc("/foo/", func(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusNoContent)
})
s := httptest.NewServer(mux)
defer s.Close()

steps := []IStep{
BaseURL("%s/foo", s.URL),
Get("/"),
Expect().Status().Equal(http.StatusNoContent),
}

Test(t, steps...)
Test(t, steps...)
}

func TestFormatURL(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/foo", func(writer http.ResponseWriter, request *http.Request) {
Expand Down
9 changes: 5 additions & 4 deletions static.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func BaseURL(url string, a ...interface{}) IStep {
CallPath: newCallPath("BaseURL", nil),
Exec: func(hit *hitImpl) error {
if len(a) > 0 {
url = fmt.Sprintf(url, a...)
hit.baseURL = fmt.Sprintf(url, a...)
return nil
}
hit.baseURL = url
return nil
Expand Down Expand Up @@ -198,13 +199,13 @@ func makeMethodStep(fnName, method, url string, a ...interface{}) IStep {
CallPath: newCallPath(fnName, nil),
Exec: func(hit *hitImpl) error {
hit.request.Method = method
url = misc.MakeURL(hit.baseURL, url, a...)
if url == "" {
u := misc.MakeURL(hit.baseURL, url, a...)
if u == "" {
hit.request.URL = new(urlpkg.URL)
return nil
}
var err error
hit.request.URL, err = urlpkg.Parse(url)
hit.request.URL, err = urlpkg.Parse(u)
if err != nil {
return err
}
Expand Down

0 comments on commit 0ee4d6e

Please sign in to comment.