Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [#441] Optimize the HTTP testing process [#2] #708

Merged
merged 13 commits into from
Nov 2, 2024
5 changes: 5 additions & 0 deletions contracts/testing/assertable_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package testing

type AssertableJSON interface {
Json() map[string]any
}
12 changes: 12 additions & 0 deletions contracts/testing/test_request.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package testing

import (
"context"
"io"
)

type TestRequest interface {
WithHeaders(headers map[string]string) TestRequest
WithHeader(key, value string) TestRequest
WithoutHeader(key string) TestRequest
WithCookies(cookies map[string]string) TestRequest
WithCookie(key, value string) TestRequest
WithContext(ctx context.Context) TestRequest
Get(uri string) (TestResponse, error)
Post(uri string, body io.Reader) (TestResponse, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body io.Reader is a bit difficult to build. Can we provide a simple way to do so?

image

Copy link
Member Author

@kkumar-gcc kkumar-gcc Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can provide a interface to write body. (May be in next PR?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can optimize it in another PR if you want.

Put(uri string, body io.Reader) (TestResponse, error)
Patch(uri string, body io.Reader) (TestResponse, error)
Delete(uri string, body io.Reader) (TestResponse, error)
Head(uri string, body io.Reader) (TestResponse, error)
Options(uri string) (TestResponse, error)
kkumar-gcc marked this conversation as resolved.
Show resolved Hide resolved
}
17 changes: 13 additions & 4 deletions contracts/testing/test_response.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package testing

type TestResponse interface {
IsSuccessful() bool
IsServerError() bool
Content() (string, error)
Json() (map[string]any, error)
AssertStatus(status int) TestResponse
AssertOk() TestResponse
AssertCreated() TestResponse
Expand All @@ -27,9 +31,14 @@ type TestResponse interface {
AssertInternalServerError() TestResponse
AssertServiceUnavailable() TestResponse
AssertHeader(headerName, value string) TestResponse
AssertHeaderMissing(headerName string) TestResponse
AssertHeaderMissing(string) TestResponse
AssertCookie(name, value string) TestResponse
AssertCookieExpired(name string) TestResponse
AssertCookieNotExpired(name string) TestResponse
AssertCookieMissing(name string) TestResponse
AssertCookieExpired(string) TestResponse
AssertCookieNotExpired(string) TestResponse
AssertCookieMissing(string) TestResponse
AssertSuccessful() TestResponse
AssertServerError() TestResponse
AssertDontSee([]string, ...bool) TestResponse
AssertSee([]string, ...bool) TestResponse
AssertSeeInOrder([]string, ...bool) TestResponse
kkumar-gcc marked this conversation as resolved.
Show resolved Hide resolved
}
79 changes: 79 additions & 0 deletions mocks/testing/AssertableJSON.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading