@@ -139,7 +139,7 @@ Further reading:
139
139
makes ` httpmock ` more powerful and convenient than ever. When writing expectations for the header or the payload, you
140
140
can use any kind of matchers for your needs.
141
141
142
- For example, the ` Request.WithHeader(header string, value interface{} ) ` means you expect a header that matches a value,
142
+ For example, the ` Request.WithHeader(header string, value any ) ` means you expect a header that matches a value,
143
143
you can put any of these into the ` value ` :
144
144
145
145
| Type | Explanation | Example |
@@ -209,7 +209,7 @@ the [`matcher.Matcher`](https://github.com/nhatthm/go-matcher/blob/master/matche
209
209
210
210
### Request URI
211
211
212
- Use the ` Server.Expect(method string, requestURI interface{} ) ` , or ` Server.Expect[METHOD](requestURI interface{} ) ` to
212
+ Use the ` Server.Expect(method string, requestURI any ) ` , or ` Server.Expect[METHOD](requestURI any ) ` to
213
213
start a new expectation. You can put a ` string ` , a ` []byte ` or a [ ` matcher.Matcher ` ] ( #match-a-value ) for
214
214
the ` requestURI ` . If the ` value ` is a ` string ` or a ` []byte ` , the URI is checked by using the [ ` matcher.Exact ` ] ( #exact ) .
215
215
@@ -241,8 +241,8 @@ func TestSimple(t *testing.T) {
241
241
242
242
To check whether the header of the incoming request matches some values. You can use:
243
243
244
- - ` Request.WithHeader(key string, value interface{} ) ` : to match a single header.
245
- - ` Request.WithHeaders(header map[string]interface{} ) ` : to match multiple headers.
244
+ - ` Request.WithHeader(key string, value any ) ` : to match a single header.
245
+ - ` Request.WithHeaders(header map[string]any ) ` : to match multiple headers.
246
246
247
247
The ` value ` could be ` string ` , ` []byte ` , or a [ ` matcher.Matcher ` ] ( #match-a-value ) . If the ` value ` is a ` string ` or
248
248
a ` []byte ` , the header is checked by using the [ ` matcher.Exact ` ] ( #exact ) .
@@ -274,11 +274,11 @@ func TestSimple(t *testing.T) {
274
274
275
275
There are several ways to match a request body:
276
276
277
- - ` WithBody(body interface{} ) ` : The expected body can be a ` string ` , a ` []byte ` or a [ ` matcher.Matcher ` ] ( #match-a-value )
277
+ - ` WithBody(body any ) ` : The expected body can be a ` string ` , a ` []byte ` or a [ ` matcher.Matcher ` ] ( #match-a-value )
278
278
. If it is a ` string ` or a ` []byte ` , the request body is checked by [ ` matched.Exact ` ] ( #exact ) .
279
- - ` WithBodyf(format string, args ...interface{} ) ` : Old school ` fmt.Sprintf() ` call, the request body is checked
279
+ - ` WithBodyf(format string, args ...any ) ` : Old school ` fmt.Sprintf() ` call, the request body is checked
280
280
by [ ` matched.Exact ` ] ( #exact ) with the result from ` fmt.Sprintf() ` .
281
- - ` WithBodyJSON(body interface{} ) ` : The expected body will be marshaled using ` json.Marshal() ` and the request body is
281
+ - ` WithBodyJSON(body any ) ` : The expected body will be marshaled using ` json.Marshal() ` and the request body is
282
282
checked by [ ` matched.JSON ` ] ( #json ) .
283
283
284
284
For example:
@@ -316,7 +316,7 @@ import (
316
316
func TestSimple (t *testing .T ) {
317
317
srv := httpmock.New (func (s *httpmock.Server ) {
318
318
s.ExpectPost (" /users" ).
319
- WithBodyJSON (map [string ]interface {} {" id" : 42 })
319
+ WithBodyJSON (map [string ]any {" id" : 42 })
320
320
})(t)
321
321
322
322
// Your request and assertions.
@@ -392,8 +392,8 @@ There are several ways to create a response for the request
392
392
| Method | Explanation | Example |
393
393
| :----------------------------------------------| :--------------------------------------------------------------------------| :---------------------------------------------------------------------------------------|
394
394
| ` Return(v string,bytes,fmt.Stringer) ` | Nothing fancy, the response is the given string | ` Return("hello world") ` |
395
- | ` Returnf(format string, args ...interface{} ) ` | Same as ` Return() ` , but with support for formatting using ` fmt.Sprintf() ` | ` Returnf("hello %s", "world") ` |
396
- | ` ReturnJSON(v interface{} ) ` | The response is the result of ` json.Marshal(v) ` | ` ReturnJSON(map[string]string{"name": "john"}) ` |
395
+ | ` Returnf(format string, args ...any ) ` | Same as ` Return() ` , but with support for formatting using ` fmt.Sprintf() ` | ` Returnf("hello %s", "world") ` |
396
+ | ` ReturnJSON(v any ) ` | The response is the result of ` json.Marshal(v) ` | ` ReturnJSON(map[string]string{"name": "john"}) ` |
397
397
| ` ReturnFile(path string) ` | The response is the content of given file, read by ` io.ReadFile() ` | ` ReturnFile("resources/fixtures/result.json") ` |
398
398
| ` Run(func(r *http.Request) ([]byte, error)) ` | Custom Logic | [ See the example] ( https://github.com/nhatthm/httpmock/blob/master/example_test.go#L44 ) |
399
399
@@ -497,7 +497,7 @@ func TestCustomResponse(t *testing.T) {
497
497
WithBody (` {"name":"John Doe"}` ).
498
498
After (time.Second ).
499
499
ReturnCode (httpmock.StatusCreated ).
500
- ReturnJSON (map [string ]interface {} {
500
+ ReturnJSON (map [string ]any {
501
501
" id" : 1 ,
502
502
" name" : " John Doe" ,
503
503
})
@@ -527,7 +527,7 @@ func TestExpectationsWereNotMet(t *testing.T) {
527
527
WithHeader (" Authorization" , " Bearer token" ).
528
528
WithBody (` {"name":"John Doe"}` ).
529
529
After (time.Second ).
530
- ReturnJSON (map [string ]interface {} {
530
+ ReturnJSON (map [string ]any {
531
531
" id" : 1 ,
532
532
" name" : " John Doe" ,
533
533
})
0 commit comments