Skip to content

Commit

Permalink
ref(test): Add TestManager struct for uniform test setup
Browse files Browse the repository at this point in the history
Add `TestManager` to manage setting up Mocks and Trycmd tests. This will make bumping to new Mockito #2223 easier
  • Loading branch information
szokeasaurusrex committed Nov 15, 2024
1 parent 67ca9e7 commit 6c15b5b
Show file tree
Hide file tree
Showing 45 changed files with 1,327 additions and 1,071 deletions.
4 changes: 2 additions & 2 deletions tests/integration/bash_hook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::integration::register_test;
use crate::integration::TestManager;

#[test]
fn command_bash_hook() {
register_test("bash_hook/*.trycmd");
TestManager::new().register_trycmd_test("bash_hook/*.trycmd");
}
59 changes: 35 additions & 24 deletions tests/integration/debug_files/bundle_jvm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::integration::{
copy_recursively, mock_common_upload_endpoints, register_test, ServerBehavior,
};
use crate::integration::{copy_recursively, ServerBehavior, TestManager};
use std::fs::{create_dir, remove_dir_all, write};

#[test]
Expand All @@ -16,9 +14,13 @@ fn command_bundle_jvm_out_not_found_creates_dir() {
testcase_cwd_path.join("jvm"),
)
.unwrap();
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-output-not-found.trycmd");

TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test(
"debug_files/bundle_jvm/debug_files-bundle-jvm-output-not-found.trycmd",
)
.with_default_token();
}

#[test]
Expand All @@ -31,24 +33,29 @@ fn command_bundle_jvm_fails_out_is_file() {
}
copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap();
write(testcase_cwd_path.join("file.txt"), "some file content").unwrap();
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());

register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-output-is-file.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test("debug_files/bundle_jvm/debug_files-bundle-jvm-output-is-file.trycmd")
.with_default_token();
}

#[test]
fn command_bundle_jvm_fails_input_not_found() {
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-input-not-found.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test(
"debug_files/bundle_jvm/debug_files-bundle-jvm-input-not-found.trycmd",
)
.with_default_token();
}

#[test]
fn command_bundle_jvm_fails_input_is_file() {
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-input-is-file.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test("debug_files/bundle_jvm/debug_files-bundle-jvm-input-is-file.trycmd")
.with_default_token();
}

#[test]
Expand All @@ -61,16 +68,19 @@ fn command_bundle_jvm_input_dir_empty() {
}
copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap();
create_dir(testcase_cwd_path.join("empty-dir")).unwrap();
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-input-dir-empty.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test(
"debug_files/bundle_jvm/debug_files-bundle-jvm-input-dir-empty.trycmd",
)
.with_default_token();
}

#[test]
fn command_bundle_jvm_fails_invalid_uuid() {
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm-invalid-uuid.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test("debug_files/bundle_jvm/debug_files-bundle-jvm-invalid-uuid.trycmd");
}

#[test]
Expand All @@ -81,7 +91,8 @@ fn command_bundle_jvm() {
remove_dir_all(testcase_cwd_path).unwrap();
}
copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap();
let _upload_endpoints =
mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default());
register_test("debug_files/bundle_jvm/debug_files-bundle-jvm.trycmd");
TestManager::new()
.mock_common_upload_endpoints(ServerBehavior::Legacy, Default::default())
.register_trycmd_test("debug_files/bundle_jvm/debug_files-bundle-jvm.trycmd")
.with_default_token();
}
8 changes: 4 additions & 4 deletions tests/integration/debug_files/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::integration::register_test;
use crate::integration::TestManager;

mod bundle_jvm;
mod upload;

#[test]
fn command_debug_files_help() {
register_test("debug_files/*.trycmd");
TestManager::new().register_trycmd_test("debug_files/*.trycmd");
}

#[cfg(not(windows))]
#[test]
fn command_debug_files_not_windows() {
register_test("debug_files/not_windows/*.trycmd");
TestManager::new().register_trycmd_test("debug_files/not_windows/*.trycmd");
}

#[cfg(windows)]
#[test]
fn command_debug_files_windows() {
register_test("debug_files/windows/*.trycmd");
TestManager::new().register_trycmd_test("debug_files/windows/*.trycmd");
}
197 changes: 105 additions & 92 deletions tests/integration/debug_files/upload.rs
Original file line number Diff line number Diff line change
@@ -1,148 +1,161 @@
use assert_cmd::Command;

use crate::integration::{mock_endpoint, register_test, test_utils::env, MockEndpointBuilder};
use crate::integration::{test_utils::env, MockEndpointBuilder, TestManager};

#[test]
fn command_debug_files_upload() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_file("debug_files/post-difs-assemble.json"),
);
register_test("debug_files/upload/debug_files-upload.trycmd");
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_file("debug_files/post-difs-assemble.json"),
)
.register_trycmd_test("debug_files/upload/debug_files-upload.trycmd")
.with_default_token();
}

#[test]
fn command_debug_files_upload_pdb() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_body(
r#"{
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_body(
r#"{
"5f81d6becc51980870acc9f6636ab53d26160763": {
"state": "ok",
"missingChunks": []
}
}"#,
),
);
register_test("debug_files/upload/debug_files-upload-pdb.trycmd");
register_test("debug_files/upload/debug_files-upload-pdb-include-sources.trycmd");
),
)
.register_trycmd_test("debug_files/upload/debug_files-upload-pdb.trycmd")
.register_trycmd_test("debug_files/upload/debug_files-upload-pdb-include-sources.trycmd")
.with_default_token();
}

#[test]
fn command_debug_files_upload_pdb_embedded_sources() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_body(
r#"{
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_body(
r#"{
"50dd9456dc89cdbc767337da512bdb36b15db6b2": {
"state": "ok",
"missingChunks": []
}
}"#,
),
);
register_test("debug_files/upload/debug_files-upload-pdb-embedded-sources.trycmd");
),
)
.register_trycmd_test("debug_files/upload/debug_files-upload-pdb-embedded-sources.trycmd")
.with_default_token();
}

#[test]
fn command_debug_files_upload_dll_embedded_ppdb_with_sources() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_body(
r#"{
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_body(
r#"{
"fc1c9e58a65bd4eaf973bbb7e7a7cc01bfdaf15e": {
"state": "ok",
"missingChunks": []
}
}"#,
),
);
register_test("debug_files/upload/debug_files-upload-dll-embedded-ppdb-with-sources.trycmd");
),
)
.register_trycmd_test(
"debug_files/upload/debug_files-upload-dll-embedded-ppdb-with-sources.trycmd",
)
.with_default_token();
}

#[test]
fn command_debug_files_upload_mixed_embedded_sources() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_body(
r#"{
"21b76b717dbbd8c89e42d92b29667ac87aa3c124": {
"state": "ok",
"missingChunks": []
}
}"#,
),
);
// TODO this isn't tested properly at the moment, because `indicatif` ProgressBar (at least at the current version)
// swallows debug logs printed while the progress bar is active and the session is not attended.
// See how it's supposed to look like `debug_files-bundle_sources-mixed-embedded-sources.trycmd` and try it out
// after an update of `indicatif` to the latest version (currently it's blocked by some other issues).
register_test("debug_files/upload/debug_files-upload-mixed-embedded-sources.trycmd");
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_body(
r#"{
"21b76b717dbbd8c89e42d92b29667ac87aa3c124": {
"state": "ok",
"missingChunks": []
}
}"#,
),
)
// TODO this isn't tested properly at the moment, because `indicatif` ProgressBar (at least at the current version)
// swallows debug logs printed while the progress bar is active and the session is not attended.
// See how it's supposed to look like `debug_files-bundle_sources-mixed-embedded-sources.trycmd` and try it out
// after an update of `indicatif` to the latest version (currently it's blocked by some other issues).
.register_trycmd_test("debug_files/upload/debug_files-upload-mixed-embedded-sources.trycmd")
.with_default_token();
}

#[test]
fn command_debug_files_upload_no_upload() {
let _chunk_upload = mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
let _assemble = mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
TestManager::new()
.mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
)
.with_response_file("debug_files/post-difs-assemble.json"),
);
register_test("debug_files/upload/debug_files-upload-no-upload.trycmd");
.mock_endpoint(
MockEndpointBuilder::new(
"POST",
"/api/0/projects/wat-org/wat-project/files/difs/assemble/",
200,
)
.with_response_file("debug_files/post-difs-assemble.json"),
)
.register_trycmd_test("debug_files/upload/debug_files-upload-no-upload.trycmd");
}

#[test]
/// This test ensures that the correct initial call to the debug files assemble endpoint is made.
/// The mock assemble endpoint returns a 200 response simulating the case where all chunks
/// are already uploaded.
fn ensure_correct_assemble_call() {
let _chunk_upload = mock_endpoint(
let _manager = TestManager::new().mock_endpoint(
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200)
.with_response_file("debug_files/get-chunk-upload.json"),
);
Expand Down
Loading

0 comments on commit 6c15b5b

Please sign in to comment.