From 2b6eb3e5a2bd3e29839c3faa4ce42371870d5af2 Mon Sep 17 00:00:00 2001 From: Kiryl Mialeshka <8974488+meskill@users.noreply.github.com> Date: Thu, 28 Nov 2024 02:05:54 +0100 Subject: [PATCH] fix: error when .github directory doesn't exist (#62) --- Cargo.lock | 2 +- src/generate.rs | 2 -- tests/test-workflow.rs | 59 ++++++++++++++++++++---------------------- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5beb26c..983ae09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,7 +146,7 @@ version = "0.1.0" dependencies = [ "heck", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] diff --git a/src/generate.rs b/src/generate.rs index 4bac5b6..e1fdd92 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -46,8 +46,6 @@ impl Generate { .join("workflows") .join(self.name.as_str()); - let path = path.canonicalize()?; - let content = format!("{}\n{}", comment, self.workflow.to_string()?); let result = self.check_file(&path, &content); diff --git a/tests/test-workflow.rs b/tests/test-workflow.rs index b091e4b..edb1387 100644 --- a/tests/test-workflow.rs +++ b/tests/test-workflow.rs @@ -1,38 +1,35 @@ -#[cfg(test)] -mod test { - use gh_workflow::Workflow; - use pretty_assertions::assert_eq; - use serde_json::Value; +use gh_workflow::Workflow; +use pretty_assertions::assert_eq; +use serde_json::Value; - fn split(content: &str) -> (Value, Value) { - let parsed = Workflow::parse(content).unwrap(); - let actual = serde_yaml::from_str::(&parsed.to_string().unwrap()).unwrap(); - let expected = serde_yaml::from_str::(content).unwrap(); +fn split(content: &str) -> (Value, Value) { + let parsed = Workflow::parse(content).unwrap(); + let actual = serde_yaml::from_str::(&parsed.to_string().unwrap()).unwrap(); + let expected = serde_yaml::from_str::(content).unwrap(); - (actual, expected) - } + (actual, expected) +} - #[test] - fn test_workflow_bench() { - let (actual, expected) = split(include_str!("./fixtures/workflow-bench.yml")); - assert_eq!(actual, expected); - } +#[test] +fn test_workflow_bench() { + let (actual, expected) = split(include_str!("./fixtures/workflow-bench.yml")); + assert_eq!(actual, expected); +} - #[test] - fn test_workflow_ci() { - let (actual, expected) = split(include_str!("./fixtures/workflow-ci.yml")); - assert_eq!(actual, expected); - } +#[test] +fn test_workflow_ci() { + let (actual, expected) = split(include_str!("./fixtures/workflow-ci.yml")); + assert_eq!(actual, expected); +} - #[test] - fn test_workflow_demo() { - let (actual, expected) = split(include_str!("./fixtures/workflow-demo.yml")); - assert_eq!(actual, expected); - } +#[test] +fn test_workflow_demo() { + let (actual, expected) = split(include_str!("./fixtures/workflow-demo.yml")); + assert_eq!(actual, expected); +} - #[test] - fn test_workflow_rust() { - let (actual, expected) = split(include_str!("./fixtures/workflow-rust.yml")); - assert_eq!(actual, expected); - } +#[test] +fn test_workflow_rust() { + let (actual, expected) = split(include_str!("./fixtures/workflow-rust.yml")); + assert_eq!(actual, expected); }