Add a test for serializing and update snapshots.

This commit is contained in:
Bauke 2022-10-28 14:03:01 +02:00
parent 7a543409ba
commit 3f0f643a8a
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 52 additions and 0 deletions

34
tests/serialize.rs Normal file
View File

@ -0,0 +1,34 @@
use {
hooked::{Config, ExitAction, PreCommit, Task},
toml::to_string_pretty,
};
use insta::assert_snapshot;
#[test]
fn test_serialize() {
let pre_commit_command = PreCommit {
name: Some("Command Test".to_string()),
on_failure: ExitAction::Continue,
task: Task {
command: Some("exit 0".to_string()),
script: None,
},
};
let pre_commit_script = PreCommit {
name: Some("Script Test".to_string()),
on_failure: ExitAction::Stop,
task: Task {
command: None,
script: Some("test.sh".into()),
},
};
let config = Config {
general: Default::default(),
pre_commit: vec![pre_commit_command, pre_commit_script],
};
assert_snapshot!("serialize", to_string_pretty(&config).unwrap());
}

View File

@ -6,4 +6,5 @@ Config {
general: General { general: General {
directory: "hooks", directory: "hooks",
}, },
pre_commit: [],
} }

View File

@ -0,0 +1,17 @@
---
source: tests/serialize.rs
expression: to_string_pretty(&config).unwrap()
---
[general]
directory = 'hooks'
[[pre_commit]]
name = 'Command Test'
on_failure = 'continue'
command = 'exit 0'
[[pre_commit]]
name = 'Script Test'
on_failure = 'stop'
script = 'test.sh'