Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/greptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,30 @@ impl GreptimeClient {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::registry::HealthEntry;
use chrono::Utc;

#[tokio::test]
async fn test_write_health_noop_when_disabled() {
let config = GreptimeConfig::default(); // enabled = false
let client = GreptimeClient::new(&config);
let entry = HealthEntry {
status: "ok".to_string(),
ahead: 0,
behind: 0,
checked_at: Utc::now(),
};
assert!(client.write_health("repo1", &entry).await.is_ok());
}

#[tokio::test]
async fn test_write_stars_noop_when_disabled() {
let config = GreptimeConfig::default();
let client = GreptimeClient::new(&config);
assert!(client.write_stars("repo1", 42).await.is_ok());
}
}
45 changes: 44 additions & 1 deletion src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ mod tests {
local_path: PathBuf::from(path),
tags: tags.iter().map(|t| t.to_string()).collect(),
discovered_at: Utc::now(),
language: None,
language: Some("rust".to_string()),
workspace_type: "git".to_string(),
data_tier: "private".to_string(),
last_synced_at: None,
Expand Down Expand Up @@ -776,4 +776,47 @@ mod tests {
let cond = Condition::Note("todo".to_string());
assert!(eval_condition(&r, &cond, None, None, &notes).is_none());
}

#[tokio::test]
async fn test_run_json_repos_returns_all() {
use crate::registry::{RepoEntry, WorkspaceRegistry};
use chrono::Utc;
use std::path::PathBuf;

let mut conn = WorkspaceRegistry::init_in_memory().unwrap();

let repo1 = RepoEntry {
id: "repo1".to_string(),
local_path: PathBuf::from("/tmp/repo1"),
tags: vec![],
language: Some("rust".to_string()),
discovered_at: Utc::now(),
workspace_type: "git".to_string(),
data_tier: "private".to_string(),
last_synced_at: None,
stars: None,
remotes: vec![],
};
let repo2 = RepoEntry {
id: "repo2".to_string(),
local_path: PathBuf::from("/tmp/repos/repo2"),
tags: vec![],
language: Some("rust".to_string()),
discovered_at: Utc::now(),
workspace_type: "git".to_string(),
data_tier: "private".to_string(),
last_synced_at: None,
stars: None,
remotes: vec![],
};
crate::registry::repo::save_repo(&mut conn, &repo1).unwrap();
crate::registry::repo::save_repo(&mut conn, &repo2).unwrap();

let config = crate::config::Config::default();
let result = run_json(&conn, "repos", 0, 1, &config).await.unwrap();

assert_eq!(result["count"].as_u64().unwrap(), 2);
let results = result["results"].as_array().unwrap();
assert_eq!(results.len(), 2);
}
}
72 changes: 72 additions & 0 deletions src/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,78 @@ async fn test_collect_tasks_default_mode_excludes_untagged() {
assert_eq!(tasks.len(), 1);
assert_eq!(skipped.len(), 1);
assert_eq!(tasks[0].id, "managed");
assert_eq!(skipped[0].id, "untagged");
assert_eq!(skipped[0].reason, "unmanaged");
}

#[tokio::test]
async fn test_collect_tasks_exclude_reason() {
use crate::registry::{RemoteEntry, RepoEntry, WorkspaceRegistry};
use chrono::Utc;
use std::path::PathBuf;

let mut conn = WorkspaceRegistry::init_in_memory().unwrap();

let managed = RepoEntry {
id: "repo-a".to_string(),
local_path: PathBuf::from("/tmp/repo-a"),
tags: vec!["managed".to_string()],
language: Some("rust".to_string()),
discovered_at: Utc::now(),
workspace_type: "git".to_string(),
data_tier: "private".to_string(),
last_synced_at: None,
stars: None,
remotes: vec![RemoteEntry {
remote_name: "origin".to_string(),
upstream_url: Some("https://github.com/test/repo-a".to_string()),
default_branch: Some("main".to_string()),
last_sync: None,
}],
};
crate::registry::repo::save_repo(&mut conn, &managed).unwrap();

let (tasks, skipped) = tasks::collect_tasks(&conn, None, Some("repo-a"), &[]).await.unwrap();
assert_eq!(tasks.len(), 0);
assert_eq!(skipped.len(), 1);
assert_eq!(skipped[0].id, "repo-a");
assert_eq!(skipped[0].reason, "excluded");
}

#[tokio::test]
async fn test_collect_tasks_path_excluded_reason() {
use crate::registry::{RemoteEntry, RepoEntry, WorkspaceRegistry};
use chrono::Utc;

let mut conn = WorkspaceRegistry::init_in_memory().unwrap();

let tmp = std::env::temp_dir();
let repo_path = tmp.join("node_modules").join("repo-a");
let managed = RepoEntry {
id: "repo-a".to_string(),
local_path: repo_path.clone(),
tags: vec!["managed".to_string()],
language: Some("rust".to_string()),
discovered_at: Utc::now(),
workspace_type: "git".to_string(),
data_tier: "private".to_string(),
last_synced_at: None,
stars: None,
remotes: vec![RemoteEntry {
remote_name: "origin".to_string(),
upstream_url: Some("https://github.com/test/repo-a".to_string()),
default_branch: Some("main".to_string()),
last_sync: None,
}],
};
crate::registry::repo::save_repo(&mut conn, &managed).unwrap();

let exclude_paths = vec![tmp.join("node_modules").to_string_lossy().to_string()];
let (tasks, skipped) = tasks::collect_tasks(&conn, None, None, &exclude_paths).await.unwrap();
assert_eq!(tasks.len(), 0);
assert_eq!(skipped.len(), 1);
assert_eq!(skipped[0].id, "repo-a");
assert_eq!(skipped[0].reason, "path_excluded");
}

#[tokio::test]
Expand Down
4 changes: 4 additions & 0 deletions tools/invariant-checks/run-checks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ if (-not $diffFiles) {
if ($file -notmatch '\.rs$') { continue }
if ($file -match 'tests?/|_test\.rs$|benches/|examples/') { continue }

# Inline test modules (e.g. src/foo/tests.rs included via #[cfg(test)] mod tests;)
# have no #[cfg(test)] marker inside the file itself.
if ($file -match 'tests\.rs$') { continue }

# Get test line ranges for the file
$testRanges = Get-TestLineRanges $file

Expand Down
Loading