Skip to content

Commit

Permalink
feat: [#441] Optimize the HTTP testing process [#2] (#708)
Browse files Browse the repository at this point in the history
* add all http request method for testing

* chore: update mocks

* add Don't See method

* chore: update mocks

* add AssertSee

* chore: update mocks

* add test cases for new response methods

* .

* chore: update mocks

* .

---------

Co-authored-by: kkumar-gcc <kkumar-gcc@users.noreply.github.com>
  • Loading branch information
kkumar-gcc and kkumar-gcc authored Nov 2, 2024
1 parent 8b33e6b commit b461b0f
Show file tree
Hide file tree
Showing 10 changed files with 1,285 additions and 44 deletions.
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)
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) (TestResponse, error)
Options(uri string) (TestResponse, error)
}
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
}
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

0 comments on commit b461b0f

Please sign in to comment.