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

Added PATCH support with patchfile parameter #24

Merged
merged 1 commit into from
Jul 3, 2020
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,26 @@ Starting Load Test with 100000 requests using 125 concurrent users
Example hitting a POST endpoint where POST json data is defined in a file:

```bash
$ ./cassowary run -u http://localhost:8000/add-user -c 10 -n 1000 --post-file user.json
$ ./cassowary run -u http://localhost:8000/add-user -c 10 -n 1000 --postfile user.json

Starting Load Test with 1000 requests using 10 concurrent users

[ omitted for brevity ]

```

### Load Test with PATCH Data
Example hitting a PATCH endpoint where PATCH json data is defined in a file:

```bash
$ ./cassowary run -u http://localhost:8000/add-user -c 5 -n 200 --patchfile user.json

Starting Load Test with 200 requests using 5 concurrent users

[ omitted for brevity ]

```

### Specifying a Duration for the Load Test
Example specifying a *duration* for your load test, in the command below we specify that we want send 100 requests over a duration of 30 seconds:

Expand Down
11 changes: 11 additions & 0 deletions cmd/cassowary/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func validateCLI(c *cli.Context) error {
return err
}
data = fileData
} else if c.String("patchfile") != "" {
httpMethod = "PATCH"
fileData, err := readFile(c.String("patchfile"))
if err != nil {
return err
}
data = fileData
} else {
httpMethod = "GET"
}
Expand Down Expand Up @@ -279,6 +286,10 @@ func runCLI(args []string) {
Name: "postfile",
Usage: "file containing data to POST (content type will default to application/json)",
},
&cli.StringFlag{
Name: "patchfile",
Usage: "file containing data to PATCH (content type will default to application/json)",
},
&cli.StringFlag{
Name: "putfile",
Usage: "file containing data to PUT (content type will default to application/json)",
Expand Down
6 changes: 6 additions & 0 deletions pkg/client/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (c *Cassowary) runLoadTest(outPutChan chan<- durationMetrics, workerChan ch
if err != nil {
log.Fatalf("%v", err)
}
case "PATCH":
request, err = http.NewRequest("PATCH", c.BaseURL, bytes.NewBuffer(c.Data))
request.Header.Set("Content-Type", "application/json")
if err != nil {
log.Fatalf("%v", err)
}
default:
request, err = http.NewRequest("GET", c.BaseURL, nil)
if err != nil {
Expand Down