Skip to content

Commit bf5f747

Browse files
author
Stein Fletcher
committed
Revert "Support template parameters when building request URLs (#99)"
This reverts commit 5278759.
1 parent 129026f commit bf5f747

File tree

2 files changed

+16
-132
lines changed

2 files changed

+16
-132
lines changed

apitest.go

+16-49
Original file line numberDiff line numberDiff line change
@@ -237,80 +237,51 @@ func (a *APITest) Method(method string) *Request {
237237
}
238238

239239
// Get is a convenience method for setting the request as http.MethodGet
240-
func (a *APITest) Get(url string, args ...interface{}) *Request {
240+
func (a *APITest) Get(url string) *Request {
241241
a.request.method = http.MethodGet
242-
if len(args) > 0 {
243-
a.request.url = fmt.Sprintf(url, args...)
244-
} else {
245-
a.request.url = url
246-
}
242+
a.request.url = url
247243
return a.request
248244
}
249245

250246
// Post is a convenience method for setting the request as http.MethodPost
251-
func (a *APITest) Post(url string, args ...interface{}) *Request {
247+
func (a *APITest) Post(url string) *Request {
252248
r := a.request
253249
r.method = http.MethodPost
254-
if len(args) > 0 {
255-
a.request.url = fmt.Sprintf(url, args...)
256-
} else {
257-
a.request.url = url
258-
}
250+
r.url = url
259251
return r
260252
}
261253

262254
// Put is a convenience method for setting the request as http.MethodPut
263-
func (a *APITest) Put(url string, args ...interface{}) *Request {
255+
func (a *APITest) Put(url string) *Request {
264256
r := a.request
265257
r.method = http.MethodPut
266-
if len(args) > 0 {
267-
a.request.url = fmt.Sprintf(url, args...)
268-
} else {
269-
a.request.url = url
270-
}
258+
r.url = url
271259
return r
272260
}
273261

274262
// Delete is a convenience method for setting the request as http.MethodDelete
275-
func (a *APITest) Delete(url string, args ...interface{}) *Request {
263+
func (a *APITest) Delete(url string) *Request {
276264
a.request.method = http.MethodDelete
277-
if len(args) > 0 {
278-
a.request.url = fmt.Sprintf(url, args...)
279-
} else {
280-
a.request.url = url
281-
}
265+
a.request.url = url
282266
return a.request
283267
}
284268

285269
// Patch is a convenience method for setting the request as http.MethodPatch
286-
func (a *APITest) Patch(url string, args ...interface{}) *Request {
270+
func (a *APITest) Patch(url string) *Request {
287271
a.request.method = http.MethodPatch
288-
if len(args) > 0 {
289-
a.request.url = fmt.Sprintf(url, args...)
290-
} else {
291-
a.request.url = url
292-
}
272+
a.request.url = url
293273
return a.request
294274
}
295275

296276
// URL is a builder method for setting the url of the request
297-
func (r *Request) URL(url string, args ...interface{}) *Request {
298-
if len(args) > 0 {
299-
r.url = fmt.Sprintf(url, args...)
300-
} else {
301-
r.url = url
302-
}
277+
func (r *Request) URL(url string) *Request {
278+
r.url = url
303279
return r
304280
}
305281

306282
// Body is a builder method to set the request body
307-
func (r *Request) Body(b string, args ...interface{}) *Request {
283+
func (r *Request) Body(b string) *Request {
308284
r.body = b
309-
if len(args) > 0 {
310-
r.body = fmt.Sprintf(b, args...)
311-
} else {
312-
r.body = b
313-
}
314285
return r
315286
}
316287

@@ -479,13 +450,9 @@ type Response struct {
479450
// Assert is a user defined custom assertion function
480451
type Assert func(*http.Response, *http.Request) error
481452

482-
// Body is the expected response body. The optional 'args' can be used for templating
483-
func (r *Response) Body(b string, args ...interface{}) *Response {
484-
if len(args) > 0 {
485-
r.body = fmt.Sprintf(b, args...)
486-
} else {
487-
r.body = b
488-
}
453+
// Body is the expected response body
454+
func (r *Response) Body(b string) *Response {
455+
r.body = b
489456
return r
490457
}
491458

apitest_test.go

-83
Original file line numberDiff line numberDiff line change
@@ -54,69 +54,6 @@ func TestApiTest_AddsJSONBodyToRequest(t *testing.T) {
5454
End()
5555
}
5656

57-
func TestApiTest_RequestURLFormat(t *testing.T) {
58-
apitest.New().
59-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
60-
w.WriteHeader(http.StatusOK)
61-
assert.Equal(t, "/user/1234", r.URL.Path)
62-
}).
63-
Get("/user/%s", "1234").
64-
Expect(t).
65-
Status(http.StatusOK).
66-
End()
67-
68-
apitest.New().
69-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
70-
w.WriteHeader(http.StatusOK)
71-
assert.Equal(t, "/user/1234", r.URL.Path)
72-
}).
73-
Put("/user/%s", "1234").
74-
Expect(t).
75-
Status(http.StatusOK).
76-
End()
77-
78-
apitest.New().
79-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
80-
w.WriteHeader(http.StatusOK)
81-
assert.Equal(t, "/user/1234", r.URL.Path)
82-
}).
83-
Patch("/user/%s", "1234").
84-
Expect(t).
85-
Status(http.StatusOK).
86-
End()
87-
88-
apitest.New().
89-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
90-
w.WriteHeader(http.StatusOK)
91-
assert.Equal(t, "/user/1234", r.URL.Path)
92-
}).
93-
Post("/user/%s", "1234").
94-
Expect(t).
95-
Status(http.StatusOK).
96-
End()
97-
98-
apitest.New().
99-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
100-
w.WriteHeader(http.StatusOK)
101-
assert.Equal(t, "/user/1234", r.URL.Path)
102-
}).
103-
Delete("/user/%s", "1234").
104-
Expect(t).
105-
Status(http.StatusOK).
106-
End()
107-
108-
apitest.New().
109-
HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
110-
w.WriteHeader(http.StatusOK)
111-
assert.Equal(t, "/user/1234", r.URL.Path)
112-
}).
113-
Method(http.MethodGet).
114-
URL("/user/%d", 1234).
115-
Expect(t).
116-
Status(http.StatusOK).
117-
End()
118-
}
119-
12057
func TestApiTest_JSONBody(t *testing.T) {
12158
type bodyStruct struct {
12259
A int `json:"a"`
@@ -464,26 +401,6 @@ func TestApiTest_MatchesJSONResponseBody(t *testing.T) {
464401
End()
465402
}
466403

467-
func TestApiTest_MatchesJSONResponseBodyWithTemplate(t *testing.T) {
468-
handler := http.NewServeMux()
469-
handler.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
470-
w.WriteHeader(http.StatusCreated)
471-
w.Header().Set("Content-Type", "application/json")
472-
_, err := w.Write([]byte(`{"a": 12345}`))
473-
if err != nil {
474-
panic(err)
475-
}
476-
})
477-
478-
apitest.New().
479-
Handler(handler).
480-
Get("/hello").
481-
Expect(t).
482-
Body(`{"a": %d}`, 12345).
483-
Status(http.StatusCreated).
484-
End()
485-
}
486-
487404
func TestApiTest_MatchesJSONBodyFromFile(t *testing.T) {
488405
handler := http.NewServeMux()
489406
handler.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)