-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 5-pebbles/better_tests
Better Tests & Github Actions
- Loading branch information
Showing
9 changed files
with
127 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "**" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
app_tests: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
- name: Rust Toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: stable | ||
override: true | ||
- name: Install Hurl | ||
uses: gacts/install-hurl@v1 | ||
with: | ||
version: 4.1.0 | ||
- name: Run Tests | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[default.databases.user_db] | ||
# Fun Fact: In-memory Databases don't support transactions... | ||
[default.databases.db] | ||
url = "file:database/sqlite/db.sqlite?cache=shared" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::env; | ||
use std::io::{BufRead, BufReader}; | ||
use std::process::{Command, Stdio}; | ||
|
||
#[test] | ||
fn hurl_tests() { | ||
// Set the HURL_url environment variable | ||
env::set_var("HURL_url", "http://127.0.0.1:8000"); | ||
|
||
// Start cargo in the background | ||
let mut cargo_process = Command::new("cargo") | ||
.arg("run") | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to start cargo"); | ||
|
||
// capture the PID | ||
let cargo_pid = cargo_process.id(); | ||
|
||
// wait for rocket | ||
if let Some(ref mut stdout) = cargo_process.stdout { | ||
let reader = BufReader::new(stdout); | ||
for line in reader.lines() { | ||
match line { | ||
Ok(line) => { | ||
print!("{}", line); | ||
if line.contains("Rocket has launched") { | ||
break; | ||
} | ||
} | ||
Err(e) => { | ||
cargo_process | ||
.kill() | ||
.unwrap_or_else(|_| panic!("Failed to kill cargo: pid = {}", cargo_pid)); | ||
panic!("Failed to read line: {}", e); | ||
} | ||
} | ||
} | ||
} else { | ||
cargo_process | ||
.kill() | ||
.unwrap_or_else(|_| panic!("Failed to kill cargo: pid = {}", cargo_pid)); | ||
panic!("No stdout to parse..."); | ||
} | ||
|
||
// Define the test files | ||
let tests = vec![ | ||
"tests/users.hurl", | ||
"tests/invites.hurl", | ||
"tests/permissions.hurl", | ||
"tests/sessions.hurl", | ||
"tests/genres.hurl", | ||
"tests/artists.hurl", | ||
]; | ||
|
||
// Run all application tests | ||
for test in tests { | ||
let status = Command::new("hurl") | ||
.arg("--very-verbose") | ||
.arg(test) | ||
.status() | ||
.expect("Failed to execute hurl command"); | ||
|
||
// Check if the test failed | ||
if !status.success() { | ||
cargo_process | ||
.kill() | ||
.unwrap_or_else(|_| panic!("Failed to kill cargo: pid = {}", cargo_pid)); | ||
panic!("Test failed: {}", test); | ||
} | ||
} | ||
|
||
// Kill the cargo process | ||
cargo_process | ||
.kill() | ||
.unwrap_or_else(|_| panic!("Failed to kill cargo: pid = {}", cargo_pid)); | ||
} |
This file was deleted.
Oops, something went wrong.