diff --git a/README.md b/README.md index 2922dff..9406806 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ 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 @@ -198,6 +198,18 @@ Starting Load Test with 1000 requests using 10 concurrent users ``` +### 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: diff --git a/cmd/cassowary/cli.go b/cmd/cassowary/cli.go index 76dd502..09acd78 100644 --- a/cmd/cassowary/cli.go +++ b/cmd/cassowary/cli.go @@ -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" } @@ -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)", diff --git a/pkg/client/load.go b/pkg/client/load.go index c8e7d56..71a6df3 100644 --- a/pkg/client/load.go +++ b/pkg/client/load.go @@ -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 {