diff --git a/README.md b/README.md index 5ae643d..b1045b0 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ An example ripley request: ```JSON { "url": "http://localhost:8080/", - "verb": "POST", + "method": "POST", "body": "{\"foo\": \"bar\"}", "headers": { "Accept": "text/plain" @@ -58,14 +58,14 @@ An example ripley request: } ``` -`url`, `verb` and `timestamp` are required, `headers` and `body` are optional. +`url`, `method` and `timestamp` are required, `headers` and `body` are optional. `-pace` specifies rate phases in `[duration]@[rate]` format. For example, `10s@5 5m@10 1h30m@100` means replay traffic at 5x for 10 seconds, 10x for 5 minutes and 100x for one and a half hours. The run will stop either when ripley stops receiving requests from `STDIN` or when the last phase elapses, whichever happens first. Ripley writes request results as JSON Lines to `STDOUT` ```bash -echo '{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:50.9Z"}' | ./ripley | jq +echo '{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:50.9Z"}' | ./ripley | jq ``` produces @@ -75,7 +75,7 @@ produces "statusCode": 200, "latency": 3915447, "request": { - "verb": "GET", + "method": "GET", "url": "http://localhost:8080/", "body": "", "timestamp": "2021-11-08T18:59:50.9Z", diff --git a/etc/requests.jsonl b/etc/requests.jsonl index a3eeb92..ca441e0 100644 --- a/etc/requests.jsonl +++ b/etc/requests.jsonl @@ -1,10 +1,10 @@ -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:50.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:51.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:52.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:53.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:54.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:55.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:56.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "timestamp": "2021-11-08T18:59:57.9Z"} -{"url": "http://localhost:8080/", "verb": "POST", "body": "{\"foo\": \"bar\"}", "headers": {"Accept": "text/plain"}, "timestamp": "2021-11-08T18:59:58.9Z"} -{"url": "http://localhost:8080/", "verb": "GET", "headers": {"Accept": "text/plain"}, "timestamp": "2021-11-08T18:59:59.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:50.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:51.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:52.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:53.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:54.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:55.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:56.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "timestamp": "2021-11-08T18:59:57.9Z"} +{"url": "http://localhost:8080/", "method": "POST", "body": "{\"foo\": \"bar\"}", "headers": {"Accept": "text/plain"}, "timestamp": "2021-11-08T18:59:58.9Z"} +{"url": "http://localhost:8080/", "method": "GET", "headers": {"Accept": "text/plain"}, "timestamp": "2021-11-08T18:59:59.9Z"} diff --git a/pkg/request.go b/pkg/request.go index f14f1e8..5d56f28 100644 --- a/pkg/request.go +++ b/pkg/request.go @@ -28,11 +28,11 @@ import ( ) var ( - validVerbs = [9]string{"GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"} + validMethods = [9]string{"GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"} ) type request struct { - Verb string `json:"verb"` + Method string `json:"method"` Url string `json:"url"` Body string `json:"body"` Timestamp time.Time `json:"timestamp"` @@ -40,7 +40,7 @@ type request struct { } func (r *request) httpRequest() (*http.Request, error) { - req, err := http.NewRequest(r.Verb, r.Url, bytes.NewReader([]byte(r.Body))) + req, err := http.NewRequest(r.Method, r.Url, bytes.NewReader([]byte(r.Body))) if err != nil { return nil, err @@ -67,8 +67,8 @@ func unmarshalRequest(jsonRequest []byte) (*request, error) { // Validate - if !validVerb(req.Verb) { - return nil, errors.New(fmt.Sprintf("Invalid verb: %s", req.Verb)) + if !validMethod(req.Method) { + return nil, errors.New(fmt.Sprintf("Invalid method: %s", req.Method)) } if req.Url == "" { @@ -82,9 +82,9 @@ func unmarshalRequest(jsonRequest []byte) (*request, error) { return req, nil } -func validVerb(requestVerb string) bool { - for _, verb := range validVerbs { - if requestVerb == verb { +func validMethod(requestMethod string) bool { + for _, method := range validMethods { + if requestMethod == method { return true } } diff --git a/pkg/request_test.go b/pkg/request_test.go index 91fc20d..d30b524 100644 --- a/pkg/request_test.go +++ b/pkg/request_test.go @@ -23,29 +23,29 @@ import ( "time" ) -func TestUnrmarshalInvalidVerb(t *testing.T) { - jsonRequest := `{"verb": "WHAT"}` +func TestUnrmarshalInvalidMethod(t *testing.T) { + jsonRequest := `{"method": "WHAT"}` req, err := unmarshalRequest([]byte(jsonRequest)) if req != nil { t.Errorf("req = %v; want nil", req) } - if err.Error() != "Invalid verb: WHAT" { - t.Errorf(`err.Error() = %v; want "Invalid verb: WHAT"`, err.Error()) + if err.Error() != "Invalid method: WHAT" { + t.Errorf(`err.Error() = %v; want "Invalid method: WHAT"`, err.Error()) } } func TestUnrmarshalValid(t *testing.T) { - jsonRequest := `{"verb": "GET", "url": "http://example.com", "timestamp": "2021-11-08T18:59:59.9Z"}` + jsonRequest := `{"method": "GET", "url": "http://example.com", "timestamp": "2021-11-08T18:59:59.9Z"}` req, err := unmarshalRequest([]byte(jsonRequest)) if err != nil { t.Errorf("err = %v; want nil", err) } - if req.Verb != "GET" { - t.Errorf("req.Verb = %v; want GET", req.Verb) + if req.Method != "GET" { + t.Errorf("req.Method = %v; want GET", req.Method) } if req.Url != "http://example.com" {