Skip to content

Commit

Permalink
introduce GooseRequest and builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Andrews committed Oct 29, 2021
1 parent d02a25c commit 652ff5e
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 401 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## 0.14.2-dev
## 0.15.0-dev
- [#372](https://github.com/tag1consulting/goose/pull/372) de-deduplicate documentation, favoring [The Goose Book](https://book.goose.rs)
- @TODO: errors ...

## 0.14.1 October 13, 2021
- [#364](https://github.com/tag1consulting/goose/pull/364) add link from the [Developer Documentation](https://docs.rs/goose) to [The Git Book](https://book.goose.rs)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goose"
version = "0.14.2-dev"
version = "0.15.0-dev"
authors = ["Jeremy Andrews <jeremy@tag1consulting.com>"]
edition = "2018"
description = "A load testing framework inspired by Locust."
Expand Down
15 changes: 10 additions & 5 deletions examples/drupal_memcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ async fn drupal_memcache_front_page(user: &mut GooseUser) -> GooseTaskResult {
}
}
for asset in &urls {
let _ = user.get_named(asset, "static asset").await;
let _ = user
.request(
GooseRequest::builder()
.path(&*asset.to_string())
.name("static asset")
.build(),
)
.await;
}
}
Err(e) => {
Expand Down Expand Up @@ -185,8 +192,7 @@ async fn drupal_memcache_login(user: &mut GooseUser) -> GooseTaskResult {
("form_id", "user_login"),
("op", "Log+in"),
];
let request_builder = user.goose_post("/user")?;
let _goose = user.goose_send(request_builder.form(&params), None).await;
let _goose = user.post_form("/user", &params).await?;
// @TODO: verify that we actually logged in.
}
Err(e) => {
Expand Down Expand Up @@ -302,8 +308,7 @@ async fn drupal_memcache_post_comment(user: &mut GooseUser) -> GooseTaskResult {
];

// Post the comment.
let request_builder = user.goose_post(&comment_path)?;
let mut goose = user.goose_send(request_builder.form(&params), None).await?;
let mut goose = user.post_form(&comment_path, &params).await?;

// Verify that the comment posted.
match goose.response {
Expand Down
4 changes: 1 addition & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ async fn main() -> Result<(), GooseError> {
/// on_start task when registering it above. This means it only runs one time
/// per user, when the user thread first starts.
async fn website_login(user: &mut GooseUser) -> GooseTaskResult {
let request_builder = user.goose_post("/login")?;
// https://docs.rs/reqwest/*/reqwest/blocking/struct.RequestBuilder.html#method.form
let params = [("username", "test_user"), ("password", "")];
let _goose = user.goose_send(request_builder.form(&params), None).await?;
let _goose = user.post_form("/login", &params).await?;

Ok(())
}
Expand Down
13 changes: 8 additions & 5 deletions examples/simple_with_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ async fn main() -> Result<(), GooseError> {
/// on_start task when registering it above. This means it only runs one time
/// per user, when the user thread first starts.
async fn website_signup(user: &mut GooseUser) -> GooseTaskResult {
let request_builder = user.goose_post("/signup")?;
// https://docs.rs/reqwest/*/reqwest/blocking/struct.RequestBuilder.html#method.form
let params = [("username", "test_user"), ("password", "")];
let response = user
.goose_send(request_builder.form(&params), None)
.post_form("/signup", &params)
.await?
.response?
.json::<AuthenticationResponse>()
Expand All @@ -77,8 +75,13 @@ async fn authenticated_index(user: &mut GooseUser) -> GooseTaskResult {
// This will panic if the session is missing or if the session is not of the right type
// use `get_session_data` to handle missing session
let session = user.get_session_data_unchecked::<Session>();
let request = user.goose_get("/")?.bearer_auth(&session.jwt_token);
let _goose = user.goose_send(request, None).await?;
let url = user.build_url("/")?;
let request_builder = user.client.get(url).bearer_auth(&session.jwt_token);
let goose_request = GooseRequest::builder()
.request_builder(request_builder)
.build();

user.request(goose_request).await?;

Ok(())
}
9 changes: 4 additions & 5 deletions examples/umami/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub async fn log_in(user: &mut GooseUser) -> GooseTaskResult {
("form_id", &"user_login_form".to_string()),
("op", &"Log+in".to_string()),
];
let request_builder = user.goose_post("/en/user/login")?;
logged_in_user = user.goose_send(request_builder.form(&params), None).await?;
logged_in_user = user.post_form("/en/user/login", &params).await?;

// A successful log in is redirected.
if !logged_in_user.request.redirected {
Expand Down Expand Up @@ -169,9 +168,9 @@ pub async fn edit_article(user: &mut GooseUser) -> GooseTaskResult {
("form_id", &"node_article_edit_form".to_string()),
("op", &"Save (this translation)".to_string()),
];
let request_builder =
user.goose_post(&format!("/en/node/{}/edit", article.unwrap().nid))?;
saved_article = user.goose_send(request_builder.form(&params), None).await?;
saved_article = user
.post_form(&format!("/en/node/{}/edit", article.unwrap().nid), &params)
.await?;

// A successful node save is redirected.
if !saved_article.request.redirected {
Expand Down
15 changes: 10 additions & 5 deletions examples/umami/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,14 @@ pub async fn load_static_elements(user: &mut GooseUser, html: &str) {

// Load all the static assets found on the page.
for asset in &urls {
let _ = user.get_named(asset, "static asset").await;
let _ = user
.request(
GooseRequest::builder()
.path(&*asset.to_string())
.name("static asset")
.build(),
)
.await;
}
}

Expand Down Expand Up @@ -565,8 +572,7 @@ pub async fn anonymous_contact_form(user: &mut GooseUser, english: bool) -> Goos
("form_id", "contact_message_feedback_form"),
("op", "Send+message"),
];
let request_builder = user.goose_post(contact_form_url)?;
contact_form = user.goose_send(request_builder.form(&params), None).await?;
contact_form = user.post_form(contact_form_url, &params).await?;
}
Err(e) => {
return user.set_failure(
Expand Down Expand Up @@ -694,8 +700,7 @@ pub async fn search(user: &mut GooseUser, english: bool) -> GooseTaskResult {
("form_id", "search_form"),
("op", "Search"),
];
let request_builder = user.goose_post(search_form_url)?;
search_form = user.goose_send(request_builder.form(&params), None).await?;
search_form = user.post_form(search_form_url, &params).await?;

// A successful search is redirected.
if !search_form.request.redirected {
Expand Down
Loading

0 comments on commit 652ff5e

Please sign in to comment.