Skip to content

Commit 246a5a0

Browse files
authored
Merge pull request #18 from nhatthm/deprecate-request-package
Deprecate `request` package
2 parents 0b88ff0 + 880ecd1 commit 246a5a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1357
-826
lines changed

Diff for: README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Further reading:
139139
makes `httpmock` more powerful and convenient than ever. When writing expectations for the header or the payload, you
140140
can use any kind of matchers for your needs.
141141

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,
143143
you can put any of these into the `value`:
144144

145145
| Type | Explanation | Example |
@@ -209,7 +209,7 @@ the [`matcher.Matcher`](https://github.com/nhatthm/go-matcher/blob/master/matche
209209

210210
### Request URI
211211

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
213213
start a new expectation. You can put a `string`, a `[]byte` or a [`matcher.Matcher`](#match-a-value) for
214214
the `requestURI`. If the `value` is a `string` or a `[]byte`, the URI is checked by using the [`matcher.Exact`](#exact).
215215

@@ -241,8 +241,8 @@ func TestSimple(t *testing.T) {
241241

242242
To check whether the header of the incoming request matches some values. You can use:
243243

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.
246246

247247
The `value` could be `string`, `[]byte`, or a [`matcher.Matcher`](#match-a-value). If the `value` is a `string` or
248248
a `[]byte`, the header is checked by using the [`matcher.Exact`](#exact).
@@ -274,11 +274,11 @@ func TestSimple(t *testing.T) {
274274

275275
There are several ways to match a request body:
276276

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)
278278
. 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
280280
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
282282
checked by [`matched.JSON`](#json).
283283

284284
For example:
@@ -316,7 +316,7 @@ import (
316316
func TestSimple(t *testing.T) {
317317
srv := httpmock.New(func(s *httpmock.Server) {
318318
s.ExpectPost("/users").
319-
WithBodyJSON(map[string]interface{}{"id": 42})
319+
WithBodyJSON(map[string]any{"id": 42})
320320
})(t)
321321

322322
// Your request and assertions.
@@ -392,8 +392,8 @@ There are several ways to create a response for the request
392392
| Method | Explanation | Example |
393393
|:----------------------------------------------|:--------------------------------------------------------------------------|:---------------------------------------------------------------------------------------|
394394
| `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"})` |
397397
| `ReturnFile(path string)` | The response is the content of given file, read by `io.ReadFile()` | `ReturnFile("resources/fixtures/result.json")` |
398398
| `Run(func(r *http.Request) ([]byte, error))` | Custom Logic | [See the example](https://github.com/nhatthm/httpmock/blob/master/example_test.go#L44) |
399399

@@ -497,7 +497,7 @@ func TestCustomResponse(t *testing.T) {
497497
WithBody(`{"name":"John Doe"}`).
498498
After(time.Second).
499499
ReturnCode(httpmock.StatusCreated).
500-
ReturnJSON(map[string]interface{}{
500+
ReturnJSON(map[string]any{
501501
"id": 1,
502502
"name": "John Doe",
503503
})
@@ -527,7 +527,7 @@ func TestExpectationsWereNotMet(t *testing.T) {
527527
WithHeader("Authorization", "Bearer token").
528528
WithBody(`{"name":"John Doe"}`).
529529
After(time.Second).
530-
ReturnJSON(map[string]interface{}{
530+
ReturnJSON(map[string]any{
531531
"id": 1,
532532
"name": "John Doe",
533533
})

Diff for: codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ignore:
22
- "internal/mock/**/*"
3+
- "request/*"

0 commit comments

Comments
 (0)