Skip to content

Commit

Permalink
Merge pull request diesel-rs#4087 from VicVerevita/postgresql-integra…
Browse files Browse the repository at this point in the history
…tion-tests

getting started integration tests
  • Loading branch information
weiznich authored Jul 2, 2024
2 parents 99ef8bb + ea39b06 commit d4aa69d
Show file tree
Hide file tree
Showing 18 changed files with 300 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/mysql/getting_started_step_1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
10 changes: 10 additions & 0 deletions examples/mysql/getting_started_step_1/tests/step_1.rs
Original file line number Diff line number Diff line change
@@ -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");
}
3 changes: 3 additions & 0 deletions examples/mysql/getting_started_step_2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
27 changes: 27 additions & 0 deletions examples/mysql/getting_started_step_2/tests/step_2.rs
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions examples/mysql/getting_started_step_3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
54 changes: 54 additions & 0 deletions examples/mysql/getting_started_step_3/tests/step_3.rs
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions examples/postgres/getting_started_step_1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
10 changes: 10 additions & 0 deletions examples/postgres/getting_started_step_1/tests/step_1.rs
Original file line number Diff line number Diff line change
@@ -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");
}
3 changes: 3 additions & 0 deletions examples/postgres/getting_started_step_2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
27 changes: 27 additions & 0 deletions examples/postgres/getting_started_step_2/tests/step_2.rs
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions examples/postgres/getting_started_step_3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ publish = false
diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] }
dotenvy = "0.15"

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
54 changes: 54 additions & 0 deletions examples/postgres/getting_started_step_3/tests/step_3.rs
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions examples/sqlite/getting_started_step_1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ 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]]
name = "show_posts"
doc = false
Expand Down
10 changes: 10 additions & 0 deletions examples/sqlite/getting_started_step_1/tests/step_1.rs
Original file line number Diff line number Diff line change
@@ -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");
}
3 changes: 3 additions & 0 deletions examples/sqlite/getting_started_step_2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "r
dotenvy = "0.15"
libsqlite3-sys = { version = "0.28.0", features = ["bundled"] }

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
27 changes: 27 additions & 0 deletions examples/sqlite/getting_started_step_2/tests/step_2.rs
Original file line number Diff line number Diff line change
@@ -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";
3 changes: 3 additions & 0 deletions examples/sqlite/getting_started_step_3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "r
dotenvy = "0.15"
libsqlite3-sys = { version = "0.28.0", features = ["bundled"] }

[dev_dependencies]
assert_cmd = "2.0.14"

[[bin]]
name = "show_posts"
doc = false
Expand Down
54 changes: 54 additions & 0 deletions examples/sqlite/getting_started_step_3/tests/step_3.rs
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit d4aa69d

Please sign in to comment.