Skip to content

Commit

Permalink
test: add test for duplicated jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Dec 25, 2024
1 parent d3ab323 commit 49dfd17
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
43 changes: 43 additions & 0 deletions crates/gh-workflow/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,46 @@ fn find_value<'a, K, V: PartialEq>(job: &V, map: &'a IndexMap<K, V>) -> Option<&
map.iter()
.find_map(|(k, v)| if v == job { Some(k) } else { None })
}

Check warning on line 143 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/gh-workflow/gh-workflow/crates/gh-workflow/src/generate.rs
#[cfg(test)]
mod tests {
use super::*;
use insta::assert_snapshot;

#[test]
fn add_needs_job() {
let base_job = Job::new("Base job");

let job1 =
Job::new("The first job that has dependency for base_job").add_needs(base_job.clone());
let job2 =
Job::new("The second job that has dependency for base_job").add_needs(base_job.clone());

let workflow = Workflow::new("All jobs were added to workflow")
.add_job("base_job", base_job)
.add_job("with-dependency-1", job1)
.add_job("with-dependency-2", job2);

let workflow = Generate::new(workflow).workflow;

assert_snapshot!(workflow.to_string().unwrap());
}

#[test]
fn missing_add_job() {
let base_job = Job::new("Base job");

let job1 =
Job::new("The first job that has dependency for base_job").add_needs(base_job.clone());
let job2 =
Job::new("The second job that has dependency for base_job").add_needs(base_job.clone());

let workflow = Workflow::new("base_job was not added to workflow jobs")
.add_job("with-dependency-1", job1)
.add_job("with-dependency-2", job2);

let workflow = Generate::new(workflow).workflow;

assert_snapshot!(workflow.to_string().unwrap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: crates/gh-workflow/src/generate.rs
expression: workflow.to_string().unwrap()
snapshot_kind: text
---
name: All jobs were added to workflow
jobs:
base_job:
name: Base job
runs-on: ubuntu-latest
with-dependency-1:
needs:
- base_job
name: The first job that has dependency for base_job
runs-on: ubuntu-latest
with-dependency-2:
needs:
- base_job
name: The second job that has dependency for base_job
runs-on: ubuntu-latest
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: crates/gh-workflow/src/generate.rs
expression: workflow.to_string().unwrap()
snapshot_kind: text
---
name: base_job was not added to workflow jobs
jobs:
job-0:
name: Base job
runs-on: ubuntu-latest
with-dependency-1:
needs:
- job-0
name: The first job that has dependency for base_job
runs-on: ubuntu-latest
with-dependency-2:
needs:
- job-0
name: The second job that has dependency for base_job
runs-on: ubuntu-latest

0 comments on commit 49dfd17

Please sign in to comment.