From 37c896f41660a1500d7aa9508df73586d0f3a258 Mon Sep 17 00:00:00 2001 From: Bin Tang Date: Fri, 21 Jul 2023 19:21:35 +0800 Subject: [PATCH] fs: add test for filling auth Signed-off-by: Bin Tang --- rafs/src/fs.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/rafs/src/fs.rs b/rafs/src/fs.rs index e88928f7fc9..a1428470bf3 100644 --- a/rafs/src/fs.rs +++ b/rafs/src/fs.rs @@ -1082,6 +1082,57 @@ pub(crate) mod tests { Box::new(rafs) } + #[test] + fn test_fill_auth() { + let config = r#" + { + "device": { + "id": "test", + "backend": { + "type": "registry", + "config": { + "readahead": false, + "host": "docker.io", + "repo": "library/nginx", + "scheme": "https", + "proxy": { + "fallback": false + }, + "timeout": 5, + "connect_timeout": 5, + "retry_limit": 8 + } + } + }, + "mode": "direct", + "digest_validate": false, + "enable_xattr": true, + "fs_prefetch": { + "enable": true, + "threads_count": 10, + "merging_size": 131072, + "bandwidth_rate": 10485760 + } + }"#; + let rafs_config = RafsConfig::from_str(config).unwrap(); + let test_auth = "test_auth".to_string(); + let rafs_config = rafs_config.fill_auth(&Some(test_auth.clone())); + if let Err(_) = serde_json::from_value(rafs_config.device.backend.backend_config.clone()) + .map(|config: RegistryConfig| { + if config.auth.is_none() { + panic!() + } + if let Some(auth) = config.auth { + if auth != test_auth { + panic!() + } + } + }) + { + panic!("failed to serde json") + }; + } + #[test] fn it_should_create_new_rafs_fs() { let rafs = new_rafs_backend();