Skip to content

Commit 6324bcc

Browse files
committed
test(backend-gdrive): add wiremock integration tests for Backend trait
Add 13 integration tests that exercise the full Backend trait implementation against a local wiremock server rather than the real Drive API. Tests cover quota, change detection (including pagination), path metadata resolution, download, upload, create_dir, and delete. The `create_backend` config now accepts optional `base_url`, `upload_url`, and `access_token` keys so tests can redirect HTTP traffic to the mock server and bypass the macOS Keychain.
1 parent e3836e0 commit 6324bcc

4 files changed

Lines changed: 605 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/backend-gdrive/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ futures-core.workspace = true
1919

2020
[dev-dependencies]
2121
tokio = { workspace = true, features = ["test-util", "macros"] }
22+
wiremock = "0.6.5"
23+
serde_json = { workspace = true }
2224

2325
[lints]
2426
workspace = true

crates/backend-gdrive/src/lib.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ use client::DriveClient;
2727
/// - `client_id` — Google OAuth2 client ID
2828
/// - `client_secret` — Google OAuth2 client secret
2929
/// - `account` — account identifier for Keychain storage (defaults to "default")
30+
///
31+
/// Optional keys used in integration tests:
32+
/// - `base_url` — override the Drive API base URL (e.g. a local mock server)
33+
/// - `upload_url` — override the Drive upload API URL
34+
/// - `access_token` — pre-populate an access token, bypassing Keychain lookup
3035
pub fn create_backend(config: &toml::Value) -> anyhow::Result<Box<dyn Backend>> {
3136
let client_id = config
3237
.get("client_id")
@@ -44,14 +49,35 @@ pub fn create_backend(config: &toml::Value) -> anyhow::Result<Box<dyn Backend>>
4449
.unwrap_or("default")
4550
.to_string();
4651

52+
let drive = match (
53+
config.get("base_url").and_then(|v| v.as_str()),
54+
config.get("upload_url").and_then(|v| v.as_str()),
55+
) {
56+
(Some(base), Some(upload)) => DriveClient::with_urls(base.to_string(), upload.to_string()),
57+
(Some(base), None) => DriveClient::with_urls(
58+
base.to_string(),
59+
"https://www.googleapis.com/upload/drive/v3".to_string(),
60+
),
61+
_ => DriveClient::new(),
62+
};
63+
64+
let initial_tokens = config
65+
.get("access_token")
66+
.and_then(|v| v.as_str())
67+
.map(|token| auth::AuthTokens {
68+
access_token: token.to_string(),
69+
refresh_token: String::new(),
70+
expires_at: chrono::Utc::now() + chrono::Duration::hours(24),
71+
});
72+
4773
Ok(Box::new(GdriveBackend {
48-
drive: DriveClient::new(),
74+
drive,
4975
oauth: auth::OAuthConfig {
5076
client_id,
5177
client_secret,
5278
},
5379
account,
54-
tokens: Arc::new(RwLock::new(None)),
80+
tokens: Arc::new(RwLock::new(initial_tokens)),
5581
}))
5682
}
5783

0 commit comments

Comments
 (0)