Skip to content

Commit c768083

Browse files
authored
Merge pull request #1061 from rylev/fix-unit-tests
Fix unit tests and run them in CI
2 parents aa0cce0 + c52f00f commit c768083

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ jobs:
5656
env:
5757
RUSTFLAGS: -Dwarnings
5858

59+
- name: Run unit tests
60+
run: cargo test --all
61+
62+
5963
test_benchmarks:
6064
strategy:
6165
matrix:

site/src/load.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,35 @@ impl SiteCtxt {
175175
}
176176
}
177177

178+
/// Calculating the missing commits.
178179
fn calculate_missing(
180+
master_commits: Vec<collector::MasterCommit>,
181+
queued_pr_commits: Vec<database::QueuedCommit>,
182+
in_progress_artifacts: Vec<ArtifactId>,
183+
all_commits: HashSet<String>,
184+
) -> Vec<(Commit, MissingReason)> {
185+
calculate_missing_from(
186+
master_commits,
187+
queued_pr_commits,
188+
in_progress_artifacts,
189+
all_commits,
190+
Utc::now(),
191+
)
192+
}
193+
194+
/// Calculate the missing commits filtering out any that are 29 days or older than the supplied time.
195+
///
196+
/// This is used by `calculate_missing` is exists as a separate function for testing purposes.
197+
fn calculate_missing_from(
179198
master_commits: Vec<collector::MasterCommit>,
180199
queued_pr_commits: Vec<database::QueuedCommit>,
181200
in_progress_artifacts: Vec<ArtifactId>,
182201
mut all_commits: HashSet<String>,
202+
time: chrono::DateTime<chrono::Utc>,
183203
) -> Vec<(Commit, MissingReason)> {
184-
let now = Utc::now();
185204
let mut master_commits = master_commits
186205
.into_iter()
187-
.filter(|c| now.signed_duration_since(c.time) < Duration::days(29))
206+
.filter(|c| time.signed_duration_since(c.time) < Duration::days(29))
188207
.map(|c| {
189208
(
190209
Commit {
@@ -359,11 +378,12 @@ mod tests {
359378
];
360379
assert_eq!(
361380
expected,
362-
calculate_missing(
381+
calculate_missing_from(
363382
master_commits,
364383
queued_pr_commits,
365384
in_progress_artifacts,
366-
all_commits
385+
all_commits,
386+
time
367387
)
368388
);
369389
}

0 commit comments

Comments
 (0)