xref: /DADK/dadk-config/tests/test_user_config.rs (revision afbf76c12fc99a80f89216143547fd6a91ae86f1)
1 use std::path::PathBuf;
2 
3 use dadk_config::{
4     common::{
5         target_arch::TargetArch,
6         task::{
7             BuildConfig, CleanConfig, Dependency, InstallConfig, Source, TaskEnv, TaskSource,
8             TaskSourceType,
9         },
10     },
11     user::UserConfigFile,
12 };
13 use test_base::{
14     dadk_config::DadkConfigTestContext,
15     test_context::{self as test_context, test_context},
16 };
17 
18 const USER_CONFIG_LOCAL_FILE: &str = "config/userapp_config.toml";
19 
20 /// 测试解析DADK用户配置文件
21 #[test_context(DadkConfigTestContext)]
22 #[test]
23 fn test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext) {
24     let config_file = ctx.templates_dir().join(USER_CONFIG_LOCAL_FILE);
25     assert!(config_file.exists());
26     assert!(config_file.is_file());
27     let r = UserConfigFile::load(&config_file);
28     assert!(r.is_ok());
29     let mut user_config = r.unwrap();
30     let mut expected_user_config = UserConfigFile {
31         name: "userapp_config".to_string(),
32         version: "0.2.0".to_string(),
33         description: "".to_string(),
34         build_once: false,
35         install_once: false,
36         task_source: TaskSource {
37             source_type: TaskSourceType::BuildFromSource,
38             source: Source::Git,
39             source_path: "https://git.mirrors.dragonos.org.cn/DragonOS-Community/test_git.git"
40                 .to_string(),
41             branch: None,
42             revision: Some("01cdc56863".to_string()),
43         },
44         depends: vec![
45             Dependency {
46                 name: "depend1".to_string(),
47                 version: "0.1.1".to_string(),
48             },
49             Dependency {
50                 name: "depend2".to_string(),
51                 version: "0.1.2".to_string(),
52             },
53         ],
54         build: BuildConfig::new(Some("make install".to_string())),
55         install: InstallConfig::new(Some(PathBuf::from("/bin"))),
56         clean: CleanConfig::new(Some("make clean".to_string())),
57         envs: vec![
58             TaskEnv::new("PATH".to_string(), "/usr/bin".to_string()),
59             TaskEnv::new("LD_LIBRARY_PATH".to_string(), "/usr/lib".to_string()),
60         ],
61         target_arch: vec![TargetArch::try_from("x86_64").unwrap()],
62     };
63 
64     user_config.target_arch.sort();
65     expected_user_config.target_arch.sort();
66     user_config.depends.sort();
67     expected_user_config.depends.sort();
68     user_config.envs.sort();
69     expected_user_config.envs.sort();
70 
71     assert_eq!(user_config, expected_user_config)
72 }
73