Skip to content

Commit

Permalink
Merge pull request #3 from amad/feat/testcase-schema
Browse files Browse the repository at this point in the history
refactor: update testcase schema
  • Loading branch information
amad committed Mar 1, 2020
2 parents 717b0b3 + ee1e262 commit d888f83
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ smoker -testsuite smoke-api.json
Using docker image:

```bash
docker run --rm -v $(PWD):/data stunt/smoker:latest -testsuite /data/smoke-api.json
docker run --rm -v $(PWD):/data stunt/smoker -testsuite /data/smoke-api.json
```

Run with 15 workers and set global timeout to 5 seconds:
Expand Down Expand Up @@ -111,7 +111,7 @@ A test case can have all the following parameters to give you more control on wh
"github",
"[a-z]"
],
"header": {
"headers": {
"Content-Type": "application/json"
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ Example:
"Page not found",
"[a-z]"
],
"header": {
"headers": {
"Content-Type": "application/json",
"X-Requestid": "*"
}
Expand Down
2 changes: 1 addition & 1 deletion core/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ type TestCase struct {
type Assertions struct {
StatusCode int `json:"statusCode"`
Body []string `json:"body"`
Header map[string]string `json:"header"`
Headers map[string]string `json:"headers"`
}
36 changes: 36 additions & 0 deletions examples/example-smoketestsuite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"tests": [
{
"name": "Github.com is live",
"url": "https://github.com"
},
{
"name": "Github.com about shows copyright notice",
"url": "https://github.com/about",
"assertions": {
"body": [
"© [0-9]{4} GitHub, Inc\\."
]
}
},
{
"name": "Github repos API does not accept POST request",
"url": "https://api.github.com/repos/amad/smoker",
"method": "post",
"headers": {
"Accept": "application/json"
},
"assertions": {
"statusCode": 404
}
},
{
"name": "Github fetch user. This fails without valid token",
"url": "https://api.github.com/user",
"method": "post",
"headers": {
"Authorization": "token GITHUB_TOKEN_PLACEHOLDER"
}
}
]
}
4 changes: 2 additions & 2 deletions requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (r *Requester) Request(tc core.TestCase) (bool, error) {
}
}

if len(tc.Assertions.Header) != 0 {
for expectedHeaderName, expectedHeaderValue := range tc.Assertions.Header {
if len(tc.Assertions.Headers) != 0 {
for expectedHeaderName, expectedHeaderValue := range tc.Assertions.Headers {
canonicalHeaderName := textproto.CanonicalMIMEHeaderKey(expectedHeaderName)

headerValue, foundHeader := res.Header[canonicalHeaderName]
Expand Down
6 changes: 3 additions & 3 deletions requester/requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestRequest(t *testing.T) {
Name: "test",
URL: "example.com",
Assertions: core.Assertions{
Header: map[string]string{"Content-Type": "application/json"},
Headers: map[string]string{"Content-Type": "application/json"},
},
},
mockStatusCode: 200,
Expand All @@ -135,7 +135,7 @@ func TestRequest(t *testing.T) {
Name: "test",
URL: "example.com",
Assertions: core.Assertions{
Header: map[string]string{"Content-Type": "application/json"},
Headers: map[string]string{"Content-Type": "application/json"},
},
},
mockStatusCode: 200,
Expand All @@ -147,7 +147,7 @@ func TestRequest(t *testing.T) {
Name: "test",
URL: "example.com",
Assertions: core.Assertions{
Header: map[string]string{"access-control-allow-origin": "*", "content-length": "[0-9]+"},
Headers: map[string]string{"access-control-allow-origin": "*", "content-length": "[0-9]+"},
},
},
mockStatusCode: 200,
Expand Down

0 comments on commit d888f83

Please sign in to comment.