Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for duplicated jobs #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
44 changes: 44 additions & 0 deletions crates/gh-workflow/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,47 @@ 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 })
}

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use super::*;

#[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
Loading