Skip to content

Commit

Permalink
Merge branch 'main' into make-to-ci-workflow-public
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop authored Dec 29, 2024
2 parents 47136b3 + eb7f139 commit 04e1d51
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
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

0 comments on commit 04e1d51

Please sign in to comment.