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

Fix static check #9

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .octocov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
coverage:
if: true
acceptable: 80%
badge:
path: docs/coverage.svg
testExecutionTime:
if: true
acceptable: 1:1.1
acceptable: current <= 1min && diff <= 2sec
badge:
path: docs/time.svg
diff:
datastores:
- artifact://${GITHUB_REPOSITORY}
Expand All @@ -17,12 +18,6 @@ report:
if: is_default_branch
datastores:
- artifact://${GITHUB_REPOSITORY}
coverage:
badge:
path: docs/coverage.svg
codeToTestRatio:
badge:
path: docs/ratio.svg
testExecutionTime:
badge:
path: docs/time.svg
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ go get -u github.com/go-spectest/spectest

| Example | Comment |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [gin](https://github.com/go-spectest/apitest/tree/master/examples/gin) | popular martini-like web framework |
| [graphql](https://github.com/go-spectest/apitest/tree/master/examples/graphql) | using gqlgen.com to generate a graphql server |
| [gorilla](https://github.com/go-spectest/apitest/tree/master/examples/gorilla) | the gorilla web toolkit |
| [iris](https://github.com/go-spectest/apitest/tree/master/examples/iris) | iris web framework |
| [echo](https://github.com/go-spectest/apitest/tree/master/examples/echo) | High performance, extensible, minimalist Go web framework |
| [fiber](https://github.com/go-spectest/go-spectest/tree/master/examples/fiber) | Express inspired web framework written in Go |
| [httprouter](https://github.com/go-spectest/apitest/tree/master/examples/httprouter) | High performance HTTP request router that scales well |
| [mocks](https://github.com/go-spectest/apitest/tree/master/examples/mocks) | example mocking out external http calls |
| [sequence diagrams](https://github.com/go-spectest/apitest/tree/master/examples/sequence-diagrams) | generate sequence diagrams from tests |
| [Ginkgo](https://github.com/go-spectest/apitest/tree/master/examples/ginkgo) | Ginkgo BDD test framework|
| [gin](https://github.com/go-spectest/spectest/tree/master/examples/gin) | popular martini-like web framework |
| [graphql](https://github.com/go-spectest/spectest/tree/master/examples/graphql) | using gqlgen.com to generate a graphql server |
| [gorilla](https://github.com/go-spectest/spectest/tree/master/examples/gorilla) | the gorilla web toolkit |
| [iris](https://github.com/go-spectest/spectest/tree/master/examples/iris) | iris web framework |
| [echo](https://github.com/go-spectest/spectest/tree/master/examples/echo) | High performance, extensible, minimalist Go web framework |
| [fiber](https://github.com/go-spectest/spectest/tree/master/examples/fiber) | Express inspired web framework written in Go |
| [httprouter](https://github.com/go-spectest/spectest/tree/master/examples/httprouter) | High performance HTTP request router that scales well |
| [mocks](https://github.com/go-spectest/spectest/tree/master/examples/mocks) | example mocking out external http calls |
| [sequence diagrams](https://github.com/go-spectest/spectest/tree/master/examples/sequence-diagrams) | generate sequence diagrams from tests |
| [Ginkgo](https://github.com/go-spectest/spectest/tree/master/examples/ginkgo) | Ginkgo BDD test framework|

### Companion libraries

Expand All @@ -67,7 +67,7 @@ This library was influenced by the following software packages:

```go
func TestApi(t *testing.T) {
apitest.New().
spectest.New().
Handler(handler).
Get("/user/1234").
Expect(t).
Expand All @@ -85,7 +85,7 @@ Given the response is `{"a": 12345, "b": [{"key": "c", "value": "result"}]}`

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
Expect(t).
Assert(jsonpath.Contains(`$.b[? @.key=="c"].value`, "result")).
Expand All @@ -97,7 +97,7 @@ and `jsonpath.Equals` checks for value equality

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
Expect(t).
Assert(jsonpath.Equal(`$.a`, float64(12345))).
Expand All @@ -109,7 +109,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
Expect(t).
Assert(func(res *http.Response, req *http.Request) error {
Expand All @@ -124,16 +124,16 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Patch("/hello").
Expect(t).
Status(http.StatusOK).
Cookies(apitest.Cookie("ABC").Value("12345")).
Cookies(spectest.Cookie("ABC").Value("12345")).
CookiePresent("Session-Token").
CookieNotPresent("XXX").
Cookies(
apitest.Cookie("ABC").Value("12345"),
apitest.Cookie("DEF").Value("67890"),
spectest.Cookie("ABC").Value("12345"),
spectest.Cookie("DEF").Value("67890"),
).
End()
}
Expand All @@ -143,7 +143,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
Expect(t).
Status(http.StatusOK).
Expand All @@ -155,22 +155,22 @@ func TestApi(t *testing.T) {
#### Mocking external http calls

```go
var getUser = apitest.NewMock().
var getUser = spectest.NewMock().
Get("/user/12345").
RespondWith().
Body(`{"name": "jon", "id": "1234"}`).
Status(http.StatusOK).
End()

var getPreferences = apitest.NewMock().
var getPreferences = spectest.NewMock().
Get("/preferences/12345").
RespondWith().
Body(`{"is_contactable": true}`).
Status(http.StatusOK).
End()

func TestApi(t *testing.T) {
apitest.New().
spectest.New().
Mocks(getUser, getPreferences).
Handler(handler).
Get("/hello").
Expand All @@ -186,8 +186,8 @@ func TestApi(t *testing.T) {
```go

func TestApi(t *testing.T) {
apitest.New().
Report(apitest.SequenceDiagram()).
spectest.New().
Report(spectest.SequenceDiagram()).
Mocks(getUser, getPreferences).
Handler(handler).
Get("/hello").
Expand All @@ -198,14 +198,14 @@ func TestApi(t *testing.T) {
}
```

It is possible to override the default storage location by passing the formatter instance `Report(apitest.NewSequenceDiagramFormatter(".sequence-diagrams"))`.
You can bring your own formatter too if you want to produce custom output. By default a sequence diagram is rendered on a html page. See the [demo](http://demo-html.apitest.dev.s3-website-eu-west-1.amazonaws.com/)
It is possible to override the default storage location by passing the formatter instance `Report(spectest.NewSequenceDiagramFormatter(".sequence-diagrams"))`.
You can bring your own formatter too if you want to produce custom output. By default a sequence diagram is rendered on a html page.

#### Debugging http requests and responses generated by api test and any mocks

```go
func TestApi(t *testing.T) {
apitest.New().
spectest.New().
Debug().
Handler(handler).
Get("/hello").
Expand All @@ -219,7 +219,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
BasicAuth("username", "password").
Expect(t).
Expand All @@ -232,7 +232,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
WithContext(context.TODO()).
Expect(t).
Expand All @@ -245,9 +245,9 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
Cookies(apitest.Cookie("ABC").Value("12345")).
Cookies(spectest.Cookie("ABC").Value("12345")).
Expect(t).
Status(http.StatusOK).
End()
Expand All @@ -258,7 +258,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Delete("/hello").
Headers(map[string]string{"My-Header": "12345"}).
Expect(t).
Expand All @@ -273,7 +273,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
QueryParams(map[string]string{"a": "1", "b": "2"}).
Query("c", "d").
Expand All @@ -288,7 +288,7 @@ Providing `{"a": {"b", "c", "d"}` results in parameters encoded as `a=b&a=c&a=d`

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Get("/hello").
QueryCollection(map[string][]string{"a": {"b", "c", "d"}}).
Expect(t).
Expand All @@ -301,7 +301,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Post("/hello").
FormData("a", "1").
FormData("b", "2").
Expand All @@ -317,7 +317,7 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Post("/hello").
MultipartFormData("a", "1", "2").
MultipartFile("file", "path/to/some.file1", "path/to/some.file2").
Expand All @@ -331,8 +331,8 @@ func TestApi(t *testing.T) {

```go
func TestApi(t *testing.T) {
apitest.New().
Observe(func(res *http.Response, req *http.Request, apiTest *apitest.APITest) {
spectest.New().
Observe(func(res *http.Response, req *http.Request, apiTest *spectest.APITest) {
// do something with res and req
}).
Handler(handler).
Expand All @@ -349,7 +349,7 @@ This is useful for mutating the request before it is sent to the system under te

```go
func TestApi(t *testing.T) {
apitest.Handler(handler).
spectest.Handler(handler).
Intercept(func(req *http.Request) {
req.URL.RawQuery = "a[]=xxx&a[]=yyy"
}).
Expand Down
2 changes: 1 addition & 1 deletion assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type failureMessageArgs struct {
}

// Verifier is the assertion interface allowing consumers to inject a custom assertion implementation.
// It also allows failure scenarios to be tested within apitest
// It also allows failure scenarios to be tested within spectest
type Verifier interface {
Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
True(t TestingT, value bool, msgAndArgs ...interface{}) bool
Expand Down
2 changes: 1 addition & 1 deletion assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestApiTestAssertStatusCodes(t *testing.T) {
response := &http.Response{StatusCode: status}
err := test.assertFunc(response, nil)
if test.isSuccess && err != nil {
t.Fatalf("Expecteted nil but received %s", err)
t.Fatalf("Expected nil but received %s", err)
} else if !test.isSuccess && err == nil {
t.Fatalf("Expected error but didn't receive one")
}
Expand Down
8 changes: 4 additions & 4 deletions cookies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func TestApiTestCookiesExpectedCookie(t *testing.T) {
HTTPOnly(false)

ten := 10
boolt := true
boolf := false
boolTrue := true
boolFalse := false

assert.Equal(t, Cookie{
name: toString("Tom"),
Expand All @@ -29,8 +29,8 @@ func TestApiTestCookiesExpectedCookie(t *testing.T) {
domain: toString("in.london"),
expires: &expiry,
maxAge: &ten,
secure: &boolt,
httpOnly: &boolf,
secure: &boolTrue,
httpOnly: &boolFalse,
}, *cookie)
}

Expand Down
2 changes: 1 addition & 1 deletion diagram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type FS struct {

func (m *FS) create(name string) (*os.File, error) {
m.CapturedCreateName = name
file, err := os.CreateTemp("/tmp", "apitest")
file, err := os.CreateTemp("/tmp", "spectest")
if err != nil {
panic(err)
}
Expand Down
Loading