@@ -21,6 +21,13 @@ func TestTestCase(t *testing.T) {
2121 fooRequst := atest.Request {
2222 API : urlFoo ,
2323 }
24+ defaultForm := map [string ]string {
25+ "key" : "value" ,
26+ }
27+ defaultPrepare := func () {
28+ gock .New (urlLocalhost ).
29+ Get ("/foo" ).Reply (http .StatusOK ).BodyString (`{"items":[]}` )
30+ }
2431
2532 tests := []struct {
2633 name string
@@ -41,11 +48,9 @@ func TestTestCase(t *testing.T) {
4148 name : "normal, response is map" ,
4249 testCase : & atest.TestCase {
4350 Request : atest.Request {
44- API : urlFoo ,
45- Header : map [string ]string {
46- "key" : "value" ,
47- },
48- Body : `{"foo":"bar"}` ,
51+ API : urlFoo ,
52+ Header : defaultForm ,
53+ Body : `{"foo":"bar"}` ,
4954 },
5055 Expect : atest.Response {
5156 StatusCode : http .StatusOK ,
@@ -204,10 +209,7 @@ func TestTestCase(t *testing.T) {
204209 },
205210 },
206211 },
207- prepare : func () {
208- gock .New (urlLocalhost ).
209- Get ("/foo" ).Reply (http .StatusOK ).BodyString (`{"items":[]}` )
210- },
212+ prepare : defaultPrepare ,
211213 verify : func (t * testing.T , output interface {}, err error ) {
212214 assert .NotNil (t , err )
213215 assert .Contains (t , err .Error (), "failed to get field" )
@@ -225,10 +227,7 @@ func TestTestCase(t *testing.T) {
225227 // },
226228 // },
227229 // },
228- // prepare: func() {
229- // gock.New(urlLocalhost).
230- // Get("/foo").Reply(http.StatusOK).BodyString(`{"items":[]}`)
231- // },
230+ // prepare: defaultPrepare,
232231 // verify: func(t *testing.T, output interface{}, err error) {
233232 // if assert.NotNil(t, err) {
234233 // assert.Contains(t, err.Error(), "failed to verify")
@@ -245,10 +244,7 @@ func TestTestCase(t *testing.T) {
245244 },
246245 },
247246 },
248- prepare : func () {
249- gock .New (urlLocalhost ).
250- Get ("/foo" ).Reply (http .StatusOK ).BodyString (`{"items":[]}` )
251- },
247+ prepare : defaultPrepare ,
252248 verify : func (t * testing.T , output interface {}, err error ) {
253249 assert .NotNil (t , err )
254250 assert .Contains (t , err .Error (), "unknown name println" )
@@ -263,10 +259,7 @@ func TestTestCase(t *testing.T) {
263259 },
264260 },
265261 },
266- prepare : func () {
267- gock .New (urlLocalhost ).
268- Get ("/foo" ).Reply (http .StatusOK ).BodyString (`{"items":[]}` )
269- },
262+ prepare : defaultPrepare ,
270263 verify : func (t * testing.T , output interface {}, err error ) {
271264 assert .NotNil (t , err )
272265 assert .Contains (t , err .Error (), "expected bool, but got int" )
@@ -303,9 +296,7 @@ func TestTestCase(t *testing.T) {
303296 Header : map [string ]string {
304297 util .ContentType : "multipart/form-data" ,
305298 },
306- Form : map [string ]string {
307- "key" : "value" ,
308- },
299+ Form : defaultForm ,
309300 },
310301 },
311302 prepare : func () {
@@ -322,16 +313,29 @@ func TestTestCase(t *testing.T) {
322313 Header : map [string ]string {
323314 util .ContentType : "application/x-www-form-urlencoded" ,
324315 },
325- Form : map [string ]string {
326- "key" : "value" ,
327- },
316+ Form : defaultForm ,
328317 },
329318 },
330319 prepare : func () {
331320 gock .New (urlLocalhost ).
332321 Post ("/foo" ).Reply (http .StatusOK ).BodyString (`{"items":[]}` )
333322 },
334323 verify : noError ,
324+ }, {
325+ name : "body is a template" ,
326+ testCase : & atest.TestCase {
327+ Request : atest.Request {
328+ API : urlFoo ,
329+ Method : http .MethodPost ,
330+ Body : `{"name":"{{lower "HELLO"}}"}` ,
331+ },
332+ },
333+ prepare : func () {
334+ gock .New (urlLocalhost ).
335+ Post ("/foo" ).BodyString (`{"name":"hello"}` ).
336+ Reply (http .StatusOK ).BodyString (`{}` )
337+ },
338+ verify : noError ,
335339 }}
336340 for _ , tt := range tests {
337341 t .Run (tt .name , func (t * testing.T ) {
0 commit comments