Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo-C committed Jan 20, 2024
1 parent 409f674 commit dc4aba6
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
run: cargo build
- name: Run tests
run: cargo test --verbose
- name: Run integration tests
run: |
docker compose -f docker-compose.integration.yml up -d redis playwright_dummy_server
cargo test -- --ignored
docker compose -f docker-compose.integration.yml down
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
run_integration_tests:
docker compose -f docker-compose.integration.yml up -d redis playwright_dummy_server
cargo test -- --include-ignored
docker compose -f docker-compose.integration.yml down

run_e2e_tests:
docker compose -f docker-compose.playwright.yml build jarm_online_gui
docker compose -f docker-compose.playwright.yml build jarm_online_api
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
redis:
image: redis:7-alpine
container_name: jarm_online_redis_container
command: redis-server --save 60 1 --loglevel warning
ports:
- "6379:6379"

playwright_dummy_server:
container_name: playwright_dummy_server_container
image: hugocker/nginx_tls_dummy_server:latest
ports:
- "443:443"

74 changes: 74 additions & 0 deletions tests/test_route_jarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,72 @@ mod common;
mod test_route_jarm {
use rstest::*;
use rocket::local::blocking::Client;
use rocket::serde::json::serde_json::json;
use rocket::serde::json::Value;
use crate::common::rocket_client;

const DUMMY_SERVER_JARM_HASH: &str = "21d19d00021d21d00021d19d21d21d1a46380b04d662f0848f508dd171125d";

#[rstest]
#[ignore = "Integration tests"]
fn host_as_ip_only(rocket_client: Client) {
let expected_response = json!({
"host": "127.0.0.1",
"port": "443",
"jarm_hash": DUMMY_SERVER_JARM_HASH,
"error": null,
});

let response = rocket_client.get("/jarm?host=127.0.0.1").dispatch();

assert_eq!(response.into_json::<Value>().unwrap(), expected_response);
}

#[rstest]
#[ignore = "Integration tests"]
fn host_as_domain_only(rocket_client: Client) {
let expected_response = json!({
"host": "localhost",
"port": "443",
"jarm_hash": DUMMY_SERVER_JARM_HASH,
"error": null,
});

let response = rocket_client.get("/jarm?host=localhost").dispatch();

assert_eq!(response.into_json::<Value>().unwrap(), expected_response);
}

#[rstest]
#[ignore = "Integration tests"]
fn host_as_url_only(rocket_client: Client) {
let expected_response = json!({
"host": "localhost",
"port": "443",
"jarm_hash": DUMMY_SERVER_JARM_HASH,
"error": null,
});

let response = rocket_client.get("/jarm?host=https://localhost").dispatch();

assert_eq!(response.into_json::<Value>().unwrap(), expected_response);
}

#[rstest]
#[ignore = "Integration tests"]
fn host_with_port(rocket_client: Client) {
let expected_response = json!({
"host": "localhost",
"port": "443",
"jarm_hash": DUMMY_SERVER_JARM_HASH,
"error": null,
});

let response = rocket_client.get("/jarm?host=localhost&port=443").dispatch();

assert_eq!(response.into_json::<Value>().unwrap(), expected_response);
}


#[rstest]
fn invalid_port(rocket_client: Client) {
Expand All @@ -16,4 +80,14 @@ mod test_route_jarm {

assert_eq!(response.into_string(), Some(expected_response.into()));
}

#[rstest]
#[ignore = "Integration tests"]
fn non_responding_port(rocket_client: Client) {
let expected_response = r#"{"host":"","port":"","jarm_hash":"","error":{"error_type":"Connection error","error_message":"DetailedError { underlying_error: Some(Os { code: 111, kind: ConnectionRefused, message: \"Connection refused\" }) }"}}"#;

let response = rocket_client.get("/jarm?host=localhost&port=444").dispatch();

assert_eq!(response.into_string(), Some(expected_response.into()));
}
}
1 change: 0 additions & 1 deletion tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mod test_utils {
}

#[test]
#[ignore = "Crash other tests ran in parallel"]
fn scan_timeout_in_seconds_fail_on_invalid_values() {
let _mutex = ENV_VAR_MUTEX.lock().unwrap();
env::set_var("SCAN_TIMEOUT_IN_SECONDS", "-1");
Expand Down

0 comments on commit dc4aba6

Please sign in to comment.