Skip to content

Commit

Permalink
Added PATCH support with patchfile parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rvinfoblox committed Jul 2, 2020
1 parent 90bc666 commit 61e544e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit 61e544e

Please sign in to comment.