2
0

test_user_config.rs 2.5 KB

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