From 06cb88a1a17fea7045fdfdbc7e568399ef34ce3d Mon Sep 17 00:00:00 2001 From: SteveLauC Date: Fri, 23 Jun 2023 17:04:05 +0800 Subject: [PATCH] test: test for config file creation and default config file parsing (#459) --- .github/workflows/test.yaml | 7 +++++++ src/config.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fbf0ed81..f58e12ae 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -57,3 +57,10 @@ jobs: # token: ${{ secrets.CODECOV_TOKEN }} files: ./lcov.info fail_ci_if_error: true + - name: Test creation of config file + run: | + CONFIG_PATH=~/.config/topgrade.toml; + if [ -f "$CONFIG_PATH" ]; then rm $CONFIG_PATH; fi + cargo build; + ./target/debug/topgrade --dry-run --only system; + stat $CONFIG_PATH; diff --git a/src/config.rs b/src/config.rs index 93461840..83d6d972 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1515,3 +1515,16 @@ impl Config { self.opt.custom_commands.iter().any(|s| s == name) } } + +#[cfg(test)] +mod test { + use crate::config::ConfigFile; + + /// Test the default configuration in `config.example.toml` is valid. + #[test] + fn test_default_config() { + let str = include_str!("../config.example.toml"); + + assert!(toml::from_str::(str).is_ok()); + } +}