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]
test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext)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(
55 Some("make install".to_string()),
56 Some(PathBuf::from("config/pre_build.sh")),
57 Some(PathBuf::from("config/post_build.sh")),
58 ),
59 install: InstallConfig::new(Some(PathBuf::from("/bin"))),
60 clean: CleanConfig::new(Some("make clean".to_string())),
61 envs: vec![
62 TaskEnv::new("PATH".to_string(), "/usr/bin".to_string()),
63 TaskEnv::new("LD_LIBRARY_PATH".to_string(), "/usr/lib".to_string()),
64 ],
65 target_arch: vec![TargetArch::try_from("x86_64").unwrap()],
66 };
67
68 user_config.target_arch.sort();
69 expected_user_config.target_arch.sort();
70 user_config.depends.sort();
71 expected_user_config.depends.sort();
72 user_config.envs.sort();
73 expected_user_config.envs.sort();
74
75 assert_eq!(user_config, expected_user_config)
76 }
77