tests: initial integration test setup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I082de335ed2b2bf53d687d81db0901ef6a6a6964
This commit is contained in:
parent
89d40109e5
commit
133d392df7
7 changed files with 721 additions and 5 deletions
138
tests/filter.rs
Normal file
138
tests/filter.rs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
//! Repository filtering tests.
|
||||
#![expect(clippy::expect_used)]
|
||||
|
||||
use konservejo::{core::pipeline::Pipeline, storage::Storage};
|
||||
|
||||
mod common;
|
||||
use common::{
|
||||
MockRepo,
|
||||
TestContext,
|
||||
create_test_archive,
|
||||
load_config,
|
||||
setup_mock_server,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_exclude_exact_match() {
|
||||
let archive1 = create_test_archive("include-repo");
|
||||
let archive2 = create_test_archive("exclude-repo");
|
||||
|
||||
let repos = vec![
|
||||
MockRepo::new("test-org", "include-repo", archive1),
|
||||
MockRepo::new("test-org", "exclude-repo", archive2),
|
||||
];
|
||||
let (_server, mock_url) = setup_mock_server(repos).await;
|
||||
|
||||
let ctx = TestContext::new(mock_url);
|
||||
ctx.write_config(
|
||||
&["test-org".to_string()],
|
||||
&["test-org/exclude-repo".to_string()],
|
||||
4,
|
||||
1,
|
||||
10,
|
||||
);
|
||||
|
||||
let config = load_config(&ctx).expect("Failed to load config");
|
||||
let pipeline = Pipeline::new(config)
|
||||
.await
|
||||
.expect("Failed to create pipeline");
|
||||
|
||||
let run_id = pipeline.run().await.expect("Backup failed");
|
||||
|
||||
let db_url = format!("sqlite://{}", ctx.db_path().display());
|
||||
let storage = Storage::new(&db_url)
|
||||
.await
|
||||
.expect("Failed to connect to DB");
|
||||
let jobs = storage
|
||||
.list_jobs_by_run(&run_id)
|
||||
.await
|
||||
.expect("Failed to list jobs");
|
||||
|
||||
assert_eq!(
|
||||
jobs.len(),
|
||||
1,
|
||||
"Should have 1 job (excluded repo should not be backed up)"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_exclude_wildcard_pattern() {
|
||||
let archive1 = create_test_archive("org1-repo1");
|
||||
let archive2 = create_test_archive("org1-excluded");
|
||||
let archive3 = create_test_archive("org2-excluded");
|
||||
let archive4 = create_test_archive("org2-kept");
|
||||
|
||||
let repos = vec![
|
||||
MockRepo::new("org1", "repo1", archive1),
|
||||
MockRepo::new("org1", "excluded", archive2),
|
||||
MockRepo::new("org2", "excluded", archive3),
|
||||
MockRepo::new("org2", "kept", archive4),
|
||||
];
|
||||
let (_server, mock_url) = setup_mock_server(repos).await;
|
||||
|
||||
let ctx = TestContext::new(mock_url);
|
||||
ctx.write_config(
|
||||
&["org1".to_string(), "org2".to_string()],
|
||||
&["*/excluded".to_string()],
|
||||
4,
|
||||
1,
|
||||
10,
|
||||
);
|
||||
|
||||
let config = load_config(&ctx).expect("Failed to load config");
|
||||
let pipeline = Pipeline::new(config)
|
||||
.await
|
||||
.expect("Failed to create pipeline");
|
||||
|
||||
let run_id = pipeline.run().await.expect("Backup failed");
|
||||
|
||||
let db_url = format!("sqlite://{}", ctx.db_path().display());
|
||||
let storage = Storage::new(&db_url)
|
||||
.await
|
||||
.expect("Failed to connect to DB");
|
||||
let jobs = storage
|
||||
.list_jobs_by_run(&run_id)
|
||||
.await
|
||||
.expect("Failed to list jobs");
|
||||
|
||||
assert_eq!(
|
||||
jobs.len(),
|
||||
2,
|
||||
"Should have 2 jobs (wildcard exclude should match both orgs)"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_no_excludes_backs_up_all() {
|
||||
let archive1 = create_test_archive("repo1");
|
||||
let archive2 = create_test_archive("repo2");
|
||||
let archive3 = create_test_archive("repo3");
|
||||
|
||||
let repos = vec![
|
||||
MockRepo::new("test-org", "repo1", archive1),
|
||||
MockRepo::new("test-org", "repo2", archive2),
|
||||
MockRepo::new("test-org", "repo3", archive3),
|
||||
];
|
||||
let (_server, mock_url) = setup_mock_server(repos).await;
|
||||
|
||||
let ctx = TestContext::new(mock_url);
|
||||
ctx.write_config(&["test-org".to_string()], &[], 4, 1, 10);
|
||||
|
||||
let config = load_config(&ctx).expect("Failed to load config");
|
||||
let pipeline = Pipeline::new(config)
|
||||
.await
|
||||
.expect("Failed to create pipeline");
|
||||
|
||||
let run_id = pipeline.run().await.expect("Backup failed");
|
||||
|
||||
let db_url = format!("sqlite://{}", ctx.db_path().display());
|
||||
let storage = Storage::new(&db_url)
|
||||
.await
|
||||
.expect("Failed to connect to DB");
|
||||
let jobs = storage
|
||||
.list_jobs_by_run(&run_id)
|
||||
.await
|
||||
.expect("Failed to list jobs");
|
||||
|
||||
assert_eq!(jobs.len(), 3, "Should have all 3 jobs when no excludes");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue