Skip to content

Commit

Permalink
Next BodyString extractpr
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorbin committed Feb 18, 2023
1 parent 2b18574 commit 6fa270e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Only one transformer is supported for now as a proof of concept but new ones wil

## Example


We will in this example write a test scenario that will:

- Send a GET request to `https://jsonplaceholder.typicode.com/posts`. This API returns a list of posts (you can try it by [following this link](jsonplaceholder.typicode.com/posts).
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ type HTTPAction struct {
}

type HTTPExtractors struct {
Headers map[string]string `yaml:"headers"`
BodyJSON map[string][]any `yaml:"body-json"`
Body string `yaml:"body"`
Headers map[string]string `yaml:"headers"`
BodyJSON map[string][]any `yaml:"body-json"`
Body string `yaml:"body"`
BodyString string `yaml:"body-string"`
}

type Action struct {
Expand Down
5 changes: 4 additions & 1 deletion runner/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ func ExecuteHTTP(logger *zap.Logger, store *store.Store, transformers map[string
}
}
if extractors.Body != "" {
store.Set(extractors.Body, string(responseBody))
store.Set(extractors.Body, responseBody)
}
if extractors.BodyString != "" {
store.Set(extractors.BodyString, string(responseBody))
}
return nil
}
10 changes: 6 additions & 4 deletions runner/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,17 @@ func TestExecuteHTTP(t *testing.T) {
Path: "/",
Body: `{"foo": {{ json (index .Variables "complex")}}}`,
Extractors: config.HTTPExtractors{
Body: "fullbody",
Body: "fullbody",
BodyString: "fullbodystring",
},
},
},
ExpectedBody: `{"foo": [{"a":"bcd"}]}`,
ExpectedVariables: map[string]any{
"slice": []any{float64(1), float64(2)},
"intvar": float64(1),
"fullbody": testBody,
"slice": []any{float64(1), float64(2)},
"intvar": float64(1),
"fullbody": []byte(testBody),
"fullbodystring": testBody,
},
},
}
Expand Down

0 comments on commit 6fa270e

Please sign in to comment.