From d6f143b228b3c0c732d15e7b591b8b2213d2ffec Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Thu, 27 Jun 2024 17:46:14 +0000 Subject: [PATCH 1/8] getting started integration tests --- .../getting_started_step_1/Cargo.toml | 1 + .../getting_started_step_1/tests/step_1.rs | 11 +++++ .../getting_started_step_2/Cargo.toml | 1 + .../getting_started_step_2/tests/step_2.rs | 17 +++++++ .../getting_started_step_3/Cargo.toml | 1 + .../getting_started_step_3/tests/step_3.rs | 44 +++++++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 examples/postgres/getting_started_step_1/tests/step_1.rs create mode 100644 examples/postgres/getting_started_step_2/tests/step_2.rs create mode 100644 examples/postgres/getting_started_step_3/tests/step_3.rs diff --git a/examples/postgres/getting_started_step_1/Cargo.toml b/examples/postgres/getting_started_step_1/Cargo.toml index ee57cfd7ddf4..a4c977a6e6b0 100644 --- a/examples/postgres/getting_started_step_1/Cargo.toml +++ b/examples/postgres/getting_started_step_1/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/postgres/getting_started_step_1/tests/step_1.rs b/examples/postgres/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..2f3d71245178 --- /dev/null +++ b/examples/postgres/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,11 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + diff --git a/examples/postgres/getting_started_step_2/Cargo.toml b/examples/postgres/getting_started_step_2/Cargo.toml index 9d0ded076927..18358f69a64c 100644 --- a/examples/postgres/getting_started_step_2/Cargo.toml +++ b/examples/postgres/getting_started_step_2/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/postgres/getting_started_step_2/tests/step_2.rs b/examples/postgres/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..6c985249e440 --- /dev/null +++ b/examples/postgres/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,17 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press CTRL+D when finished)\n\n\nSaved draft Test Title with id 1\n"); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + diff --git a/examples/postgres/getting_started_step_3/Cargo.toml b/examples/postgres/getting_started_step_3/Cargo.toml index 3cbdafcd031d..9a0a33bc5139 100644 --- a/examples/postgres/getting_started_step_3/Cargo.toml +++ b/examples/postgres/getting_started_step_3/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..94bfa2297b55 --- /dev/null +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,44 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press CTRL+D when finished)\n\n\nSaved draft Test Title with id 1\n"); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + From e8c98691c100931422c8f507f26f2d0f579a540f Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Thu, 27 Jun 2024 18:24:08 +0000 Subject: [PATCH 2/8] formatting changes --- examples/postgres/getting_started_step_1/tests/step_1.rs | 1 - examples/postgres/getting_started_step_2/tests/step_2.rs | 1 - examples/postgres/getting_started_step_3/tests/step_3.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/examples/postgres/getting_started_step_1/tests/step_1.rs b/examples/postgres/getting_started_step_1/tests/step_1.rs index 2f3d71245178..5a5b5a4c1183 100644 --- a/examples/postgres/getting_started_step_1/tests/step_1.rs +++ b/examples/postgres/getting_started_step_1/tests/step_1.rs @@ -8,4 +8,3 @@ fn write_post() { .append_context("show_posts", "") .stdout("Displaying 0 posts\n"); } - diff --git a/examples/postgres/getting_started_step_2/tests/step_2.rs b/examples/postgres/getting_started_step_2/tests/step_2.rs index 6c985249e440..06c14f237254 100644 --- a/examples/postgres/getting_started_step_2/tests/step_2.rs +++ b/examples/postgres/getting_started_step_2/tests/step_2.rs @@ -14,4 +14,3 @@ fn write_post() { .append_context("show_posts", "") .stdout("Displaying 0 posts\n"); } - diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs index 94bfa2297b55..157512ae0687 100644 --- a/examples/postgres/getting_started_step_3/tests/step_3.rs +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -41,4 +41,3 @@ fn write_post() { .append_context("show_posts", "") .stdout("Displaying 0 posts\n"); } - From af4c7d8f8ee4472d57defa549469169a271de30f Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Thu, 27 Jun 2024 19:53:59 +0000 Subject: [PATCH 3/8] add windows test support --- examples/postgres/getting_started_step_2/tests/step_2.rs | 8 +++++++- examples/postgres/getting_started_step_3/tests/step_3.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/postgres/getting_started_step_2/tests/step_2.rs b/examples/postgres/getting_started_step_2/tests/step_2.rs index 06c14f237254..c45707472380 100644 --- a/examples/postgres/getting_started_step_2/tests/step_2.rs +++ b/examples/postgres/getting_started_step_2/tests/step_2.rs @@ -7,10 +7,16 @@ fn write_post() { .write_stdin("Test Title\ntest text\n1 2 3") .assert() .append_context("write_post", "") - .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press CTRL+D when finished)\n\n\nSaved draft Test Title with id 1\n"); + .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press ".to_owned() + EOF + " when finished)\n\n\nSaved draft Test Title with id 1\n"); let _ = Command::cargo_bin("show_posts") .unwrap() .assert() .append_context("show_posts", "") .stdout("Displaying 0 posts\n"); } + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs index 157512ae0687..4c8100661765 100644 --- a/examples/postgres/getting_started_step_3/tests/step_3.rs +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -13,7 +13,7 @@ fn write_post() { .write_stdin("Test Title\ntest text\n1 2 3") .assert() .append_context("write_post", "") - .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press CTRL+D when finished)\n\n\nSaved draft Test Title with id 1\n"); + .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press ".to_owned() + EOF + " when finished)\n\n\nSaved draft Test Title with id 1\n"); let _ = Command::cargo_bin("publish_post") .unwrap() @@ -41,3 +41,9 @@ fn write_post() { .append_context("show_posts", "") .stdout("Displaying 0 posts\n"); } + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; From 8266d3cda7b3f65dc6211922f328731edc4d50ec Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Thu, 27 Jun 2024 20:23:50 +0000 Subject: [PATCH 4/8] formatting changes --- examples/postgres/getting_started_step_2/tests/step_2.rs | 7 ++++++- examples/postgres/getting_started_step_3/tests/step_3.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/postgres/getting_started_step_2/tests/step_2.rs b/examples/postgres/getting_started_step_2/tests/step_2.rs index c45707472380..b21a9a07e984 100644 --- a/examples/postgres/getting_started_step_2/tests/step_2.rs +++ b/examples/postgres/getting_started_step_2/tests/step_2.rs @@ -7,7 +7,12 @@ fn write_post() { .write_stdin("Test Title\ntest text\n1 2 3") .assert() .append_context("write_post", "") - .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press ".to_owned() + EOF + " when finished)\n\n\nSaved draft Test Title with id 1\n"); + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); let _ = Command::cargo_bin("show_posts") .unwrap() .assert() diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs index 4c8100661765..371ad3f58ca1 100644 --- a/examples/postgres/getting_started_step_3/tests/step_3.rs +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -13,7 +13,12 @@ fn write_post() { .write_stdin("Test Title\ntest text\n1 2 3") .assert() .append_context("write_post", "") - .stdout("What would you like your title to be?\n\nOk! Let's write Test Title (Press ".to_owned() + EOF + " when finished)\n\n\nSaved draft Test Title with id 1\n"); + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); let _ = Command::cargo_bin("publish_post") .unwrap() From d8436724c10d2fbb31b01ff1d6af3e662f985f92 Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Thu, 27 Jun 2024 21:20:44 +0000 Subject: [PATCH 5/8] add mysql tests --- .../mysql/getting_started_step_1/Cargo.toml | 1 + .../getting_started_step_1/tests/step_1.rs | 10 ++++ .../mysql/getting_started_step_2/Cargo.toml | 1 + .../getting_started_step_2/tests/step_2.rs | 27 ++++++++++ .../mysql/getting_started_step_3/Cargo.toml | 1 + .../getting_started_step_3/tests/step_3.rs | 54 +++++++++++++++++++ 6 files changed, 94 insertions(+) create mode 100644 examples/mysql/getting_started_step_1/tests/step_1.rs create mode 100644 examples/mysql/getting_started_step_2/tests/step_2.rs create mode 100644 examples/mysql/getting_started_step_3/tests/step_3.rs diff --git a/examples/mysql/getting_started_step_1/Cargo.toml b/examples/mysql/getting_started_step_1/Cargo.toml index 10909ef3bca8..cebd9b9bb0f0 100644 --- a/examples/mysql/getting_started_step_1/Cargo.toml +++ b/examples/mysql/getting_started_step_1/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/mysql/getting_started_step_1/tests/step_1.rs b/examples/mysql/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..5a5b5a4c1183 --- /dev/null +++ b/examples/mysql/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,10 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} diff --git a/examples/mysql/getting_started_step_2/Cargo.toml b/examples/mysql/getting_started_step_2/Cargo.toml index 00dd2675f1c4..82a737b02b97 100644 --- a/examples/mysql/getting_started_step_2/Cargo.toml +++ b/examples/mysql/getting_started_step_2/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/mysql/getting_started_step_2/tests/step_2.rs b/examples/mysql/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..b21a9a07e984 --- /dev/null +++ b/examples/mysql/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,27 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/mysql/getting_started_step_3/Cargo.toml b/examples/mysql/getting_started_step_3/Cargo.toml index eb9c81a25383..14ad3e8b219e 100644 --- a/examples/mysql/getting_started_step_3/Cargo.toml +++ b/examples/mysql/getting_started_step_3/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/mysql/getting_started_step_3/tests/step_3.rs b/examples/mysql/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..371ad3f58ca1 --- /dev/null +++ b/examples/mysql/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; From 5dc3a84c25938075c542ca82dc81f61ebc0e4202 Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Fri, 28 Jun 2024 21:44:01 +0000 Subject: [PATCH 6/8] add sqlite tests --- .../getting_started_step_1/tests/step_1.rs | 2 +- .../getting_started_step_3/tests/step_3.rs | 2 +- .../getting_started_step_1/tests/step_1.rs | 2 +- .../getting_started_step_3/tests/step_3.rs | 2 +- .../sqlite/getting_started_step_1/Cargo.toml | 1 + .../getting_started_step_1/tests/step_1.rs | 10 ++++ .../sqlite/getting_started_step_2/Cargo.toml | 1 + .../getting_started_step_2/tests/step_2.rs | 28 ++++++++++ .../sqlite/getting_started_step_3/Cargo.toml | 1 + .../getting_started_step_3/tests/step_3.rs | 54 +++++++++++++++++++ 10 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 examples/sqlite/getting_started_step_1/tests/step_1.rs create mode 100644 examples/sqlite/getting_started_step_2/tests/step_2.rs create mode 100644 examples/sqlite/getting_started_step_3/tests/step_3.rs diff --git a/examples/mysql/getting_started_step_1/tests/step_1.rs b/examples/mysql/getting_started_step_1/tests/step_1.rs index 5a5b5a4c1183..324d21e7d05d 100644 --- a/examples/mysql/getting_started_step_1/tests/step_1.rs +++ b/examples/mysql/getting_started_step_1/tests/step_1.rs @@ -1,7 +1,7 @@ use assert_cmd::Command; #[test] -fn write_post() { +fn show_posts() { let _ = Command::cargo_bin("show_posts") .unwrap() .assert() diff --git a/examples/mysql/getting_started_step_3/tests/step_3.rs b/examples/mysql/getting_started_step_3/tests/step_3.rs index 371ad3f58ca1..3e779c241fc4 100644 --- a/examples/mysql/getting_started_step_3/tests/step_3.rs +++ b/examples/mysql/getting_started_step_3/tests/step_3.rs @@ -1,7 +1,7 @@ use assert_cmd::Command; #[test] -fn write_post() { +fn publish_post() { let _ = Command::cargo_bin("show_posts") .unwrap() .assert() diff --git a/examples/postgres/getting_started_step_1/tests/step_1.rs b/examples/postgres/getting_started_step_1/tests/step_1.rs index 5a5b5a4c1183..324d21e7d05d 100644 --- a/examples/postgres/getting_started_step_1/tests/step_1.rs +++ b/examples/postgres/getting_started_step_1/tests/step_1.rs @@ -1,7 +1,7 @@ use assert_cmd::Command; #[test] -fn write_post() { +fn show_posts() { let _ = Command::cargo_bin("show_posts") .unwrap() .assert() diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs index 371ad3f58ca1..3e779c241fc4 100644 --- a/examples/postgres/getting_started_step_3/tests/step_3.rs +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -1,7 +1,7 @@ use assert_cmd::Command; #[test] -fn write_post() { +fn publish_post() { let _ = Command::cargo_bin("show_posts") .unwrap() .assert() diff --git a/examples/sqlite/getting_started_step_1/Cargo.toml b/examples/sqlite/getting_started_step_1/Cargo.toml index a72fddd5c3b2..f941b2ddc3bd 100644 --- a/examples/sqlite/getting_started_step_1/Cargo.toml +++ b/examples/sqlite/getting_started_step_1/Cargo.toml @@ -10,6 +10,7 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/sqlite/getting_started_step_1/tests/step_1.rs b/examples/sqlite/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..324d21e7d05d --- /dev/null +++ b/examples/sqlite/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,10 @@ +use assert_cmd::Command; + +#[test] +fn show_posts() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} diff --git a/examples/sqlite/getting_started_step_2/Cargo.toml b/examples/sqlite/getting_started_step_2/Cargo.toml index 9d645210109a..953a0888f084 100644 --- a/examples/sqlite/getting_started_step_2/Cargo.toml +++ b/examples/sqlite/getting_started_step_2/Cargo.toml @@ -9,6 +9,7 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/sqlite/getting_started_step_2/tests/step_2.rs b/examples/sqlite/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..8e78548cd264 --- /dev/null +++ b/examples/sqlite/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,28 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; + diff --git a/examples/sqlite/getting_started_step_3/Cargo.toml b/examples/sqlite/getting_started_step_3/Cargo.toml index 36a106ea72b8..968ec4bc8f76 100644 --- a/examples/sqlite/getting_started_step_3/Cargo.toml +++ b/examples/sqlite/getting_started_step_3/Cargo.toml @@ -9,6 +9,7 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +assert_cmd = "2.0.14" [[bin]] name = "show_posts" diff --git a/examples/sqlite/getting_started_step_3/tests/step_3.rs b/examples/sqlite/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..3e779c241fc4 --- /dev/null +++ b/examples/sqlite/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; + +#[test] +fn publish_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; From 1f287f5e50a2f7c099900701aff65a8aa6651d92 Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Fri, 28 Jun 2024 21:45:59 +0000 Subject: [PATCH 7/8] formatting changes --- examples/sqlite/getting_started_step_2/tests/step_2.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/sqlite/getting_started_step_2/tests/step_2.rs b/examples/sqlite/getting_started_step_2/tests/step_2.rs index 8e78548cd264..b21a9a07e984 100644 --- a/examples/sqlite/getting_started_step_2/tests/step_2.rs +++ b/examples/sqlite/getting_started_step_2/tests/step_2.rs @@ -25,4 +25,3 @@ const EOF: &str = "CTRL+D"; #[cfg(windows)] const EOF: &str = "CTRL+Z"; - From ea39b060b1e198b7341062278df74a5b772c4845 Mon Sep 17 00:00:00 2001 From: VicVerevita <0victor.gabriel01@gmail.com> Date: Tue, 2 Jul 2024 12:18:59 +0000 Subject: [PATCH 8/8] address changes --- examples/mysql/getting_started_step_1/Cargo.toml | 2 ++ examples/mysql/getting_started_step_2/Cargo.toml | 2 ++ examples/mysql/getting_started_step_3/Cargo.toml | 2 ++ examples/postgres/getting_started_step_1/Cargo.toml | 2 ++ examples/postgres/getting_started_step_2/Cargo.toml | 2 ++ examples/postgres/getting_started_step_3/Cargo.toml | 2 ++ examples/sqlite/getting_started_step_1/Cargo.toml | 2 ++ examples/sqlite/getting_started_step_2/Cargo.toml | 2 ++ examples/sqlite/getting_started_step_3/Cargo.toml | 2 ++ 9 files changed, 18 insertions(+) diff --git a/examples/mysql/getting_started_step_1/Cargo.toml b/examples/mysql/getting_started_step_1/Cargo.toml index cebd9b9bb0f0..d452c25da2ab 100644 --- a/examples/mysql/getting_started_step_1/Cargo.toml +++ b/examples/mysql/getting_started_step_1/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/mysql/getting_started_step_2/Cargo.toml b/examples/mysql/getting_started_step_2/Cargo.toml index 82a737b02b97..d07d2b704e10 100644 --- a/examples/mysql/getting_started_step_2/Cargo.toml +++ b/examples/mysql/getting_started_step_2/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/mysql/getting_started_step_3/Cargo.toml b/examples/mysql/getting_started_step_3/Cargo.toml index 14ad3e8b219e..24288748689a 100644 --- a/examples/mysql/getting_started_step_3/Cargo.toml +++ b/examples/mysql/getting_started_step_3/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/postgres/getting_started_step_1/Cargo.toml b/examples/postgres/getting_started_step_1/Cargo.toml index a4c977a6e6b0..96101d7771fd 100644 --- a/examples/postgres/getting_started_step_1/Cargo.toml +++ b/examples/postgres/getting_started_step_1/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/postgres/getting_started_step_2/Cargo.toml b/examples/postgres/getting_started_step_2/Cargo.toml index 18358f69a64c..99eb748a9813 100644 --- a/examples/postgres/getting_started_step_2/Cargo.toml +++ b/examples/postgres/getting_started_step_2/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/postgres/getting_started_step_3/Cargo.toml b/examples/postgres/getting_started_step_3/Cargo.toml index 9a0a33bc5139..5e3a8a1dbcf2 100644 --- a/examples/postgres/getting_started_step_3/Cargo.toml +++ b/examples/postgres/getting_started_step_3/Cargo.toml @@ -7,6 +7,8 @@ publish = false [dependencies] diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/sqlite/getting_started_step_1/Cargo.toml b/examples/sqlite/getting_started_step_1/Cargo.toml index f941b2ddc3bd..ae2fcfb1d653 100644 --- a/examples/sqlite/getting_started_step_1/Cargo.toml +++ b/examples/sqlite/getting_started_step_1/Cargo.toml @@ -10,6 +10,8 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/sqlite/getting_started_step_2/Cargo.toml b/examples/sqlite/getting_started_step_2/Cargo.toml index 953a0888f084..e4aacd8f23e4 100644 --- a/examples/sqlite/getting_started_step_2/Cargo.toml +++ b/examples/sqlite/getting_started_step_2/Cargo.toml @@ -9,6 +9,8 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]] diff --git a/examples/sqlite/getting_started_step_3/Cargo.toml b/examples/sqlite/getting_started_step_3/Cargo.toml index 968ec4bc8f76..df55ed256afc 100644 --- a/examples/sqlite/getting_started_step_3/Cargo.toml +++ b/examples/sqlite/getting_started_step_3/Cargo.toml @@ -9,6 +9,8 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } + +[dev_dependencies] assert_cmd = "2.0.14" [[bin]]