From 124e7dcbfdfa67aa4479961c6d5b66fcbc246a13 Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Tue, 14 Nov 2023 16:44:19 +0100 Subject: [PATCH] fix e2e, enum lint & imporved dbg print --- e2e/tests-dfx/assetscanister.bash | 15 ++++-------- .../frontend/ic-asset/src/asset/config.rs | 23 ++++++++----------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/e2e/tests-dfx/assetscanister.bash b/e2e/tests-dfx/assetscanister.bash index 628ec8ed82..a08e8bcb6e 100644 --- a/e2e/tests-dfx/assetscanister.bash +++ b/e2e/tests-dfx/assetscanister.bash @@ -1484,29 +1484,25 @@ CHERRIES" "$stdout" "match": "nevermatchme", "cache": { "max_age": 2000 - }, - "allow_raw_access": true + } }' assert_match 'WARN: 4 unmatched configurations in .*/src/e2e_project_frontend/assets/somedir/.ic-assets.json config file:' assert_contains 'WARN: { "match": "nevermatchme", "headers": {}, - "ignore": false, - "allow_raw_access": true + "ignore": false } WARN: { "match": "nevermatchmetoo", "headers": {}, - "ignore": false, - "allow_raw_access": true + "ignore": false } WARN: { "match": "non-matcher", "headers": { "x-header": "x-value" }, - "ignore": false, - "allow_raw_access": true + "ignore": false }' # splitting this up into two checks, because the order is different on macos vs ubuntu assert_contains 'WARN: { @@ -1514,8 +1510,7 @@ WARN: { "headers": { "x-header": "x-value" }, - "ignore": false, - "allow_raw_access": true + "ignore": false }' } diff --git a/src/canisters/frontend/ic-asset/src/asset/config.rs b/src/canisters/frontend/ic-asset/src/asset/config.rs index f46516b39b..286a2ae05b 100644 --- a/src/canisters/frontend/ic-asset/src/asset/config.rs +++ b/src/canisters/frontend/ic-asset/src/asset/config.rs @@ -62,19 +62,14 @@ pub struct AssetConfigRule { allow_raw_access: Option, } -#[derive(Deserialize, Debug, Clone, PartialEq, Eq)] +#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Default)] enum Maybe { Null, + #[default] Absent, Value(T), } -impl Default for Maybe { - fn default() -> Self { - Self::Absent - } -} - impl AssetConfigRule { fn applies(&self, canonical_path: &Path) -> bool { // TODO: better dot files/dirs handling, awaiting upstream changes: @@ -421,12 +416,6 @@ mod rule_utils { s.push_str(&format!(" - HTTP cache max-age: {}\n", max_age)); } } - if let Some(aliasing) = self.enable_aliasing { - s.push_str(&format!( - " - URL path aliasing: {}\n", - if aliasing { "enabled" } else { "disabled" } - )); - } if let Some(allow_raw_access) = self.allow_raw_access { s.push_str(&format!( " - enable raw access: {}\n", @@ -437,6 +426,12 @@ mod rule_utils { } )); } + if let Some(aliasing) = self.enable_aliasing { + s.push_str(&format!( + " - URL path aliasing: {}\n", + if aliasing { "enabled" } else { "disabled" } + )); + } if let Some(ref headers) = self.headers { for (key, value) in headers { s.push_str(&format!( @@ -937,7 +932,7 @@ mod with_tempdir { AssetConfig { allow_raw_access: Some(true), ..Default::default() - }, + } ); }