diff --git a/src/libaktualizr/config/config_test.cc b/src/libaktualizr/config/config_test.cc index 71904bdc0a..e72ce2f8b0 100644 --- a/src/libaktualizr/config/config_test.cc +++ b/src/libaktualizr/config/config_test.cc @@ -169,9 +169,59 @@ TEST(config, TomlConsistentNonempty) { EXPECT_EQ(conf_str1, conf_str2); } +static std::vector generate_multi_config(TemporaryDirectory &temp_dir) { + std::string content; + { + content += "[storage]\n"; + content += "path = \"path_a\"\n"; + content += "\n"; + content += "[pacman]\n"; + content += "os = \"os_a\""; + } + Utils::writeFile((temp_dir / "a_dir/a.toml"), content); + + content.clear(); + { + content += "[storage]\n"; + content += "path = \"path_z\"\n"; + content += "\n"; + content += "[pacman]\n"; + content += "sysroot = \"sysroot_z\""; + } + Utils::writeFile((temp_dir / "a_dir/z.toml"), content); + + content.clear(); + { + content += "[storage]\n"; + content += "path = \"cecond_a\""; + } + Utils::writeFile((temp_dir / "b_dir/a.toml"), content); + + content.clear(); + { + content += "[storage]\n"; + content += "path = \"latest_path\"\n"; + content += "\n"; + content += "[provision]\n"; + content += "provision_path = \"y_prov_path\""; + } + Utils::writeFile((temp_dir / "b_dir/y.toml"), content); + + content.clear(); + { + content += "[storage]\n"; + content += "path = \"this is path from text file\""; + } + Utils::writeFile((temp_dir / "b_dir/z.txt"), content); + + return std::vector{(temp_dir / "a_dir"), (temp_dir / "b_dir")}; +} /* Parse multiple config files in a directory. */ TEST(config, OneDir) { - Config config(std::vector{"tests/test_data/config_dirs/one_dir"}); + TemporaryDirectory temp_dir; + std::vector dirs = generate_multi_config(temp_dir); + + Config config(std::vector{dirs[0]}); EXPECT_EQ(config.storage.path.string(), "path_z"); EXPECT_EQ(config.pacman.sysroot.string(), "sysroot_z"); EXPECT_EQ(config.pacman.os, "os_a"); @@ -179,9 +229,10 @@ TEST(config, OneDir) { /* Parse multiple config files in multiple directories. */ TEST(config, TwoDirs) { - std::vector config_dirs{"tests/test_data/config_dirs/one_dir", - "tests/test_data/config_dirs/second_one_dir"}; - Config config(config_dirs); + TemporaryDirectory temp_dir; + std::vector dirs = generate_multi_config(temp_dir); + + Config config(dirs); EXPECT_EQ(config.storage.path.string(), "path_z"); EXPECT_EQ(config.pacman.sysroot.string(), "sysroot_z"); EXPECT_NE(config.pacman.os, "os_a"); diff --git a/tests/test_data/config_dirs/one_dir/a.toml b/tests/test_data/config_dirs/one_dir/a.toml deleted file mode 100644 index e5512c6d4e..0000000000 --- a/tests/test_data/config_dirs/one_dir/a.toml +++ /dev/null @@ -1,5 +0,0 @@ -[storage] -path = "path_a" - -[pacman] -os = "os_a" \ No newline at end of file diff --git a/tests/test_data/config_dirs/one_dir/z.toml b/tests/test_data/config_dirs/one_dir/z.toml deleted file mode 100644 index 17688462c6..0000000000 --- a/tests/test_data/config_dirs/one_dir/z.toml +++ /dev/null @@ -1,5 +0,0 @@ -[storage] -path = "path_z" - -[pacman] -sysroot = "sysroot_z" \ No newline at end of file diff --git a/tests/test_data/config_dirs/second_one_dir/a.toml b/tests/test_data/config_dirs/second_one_dir/a.toml deleted file mode 100644 index d8aa4b77bd..0000000000 --- a/tests/test_data/config_dirs/second_one_dir/a.toml +++ /dev/null @@ -1,2 +0,0 @@ -[storage] -path = "cecond_a" \ No newline at end of file diff --git a/tests/test_data/config_dirs/second_one_dir/y.toml b/tests/test_data/config_dirs/second_one_dir/y.toml deleted file mode 100644 index e48064c089..0000000000 --- a/tests/test_data/config_dirs/second_one_dir/y.toml +++ /dev/null @@ -1,5 +0,0 @@ -[storage] -path = "latest_path" - -[provision] -provision_path = "y_prov_path" \ No newline at end of file diff --git a/tests/test_data/config_dirs/second_one_dir/z.txt b/tests/test_data/config_dirs/second_one_dir/z.txt deleted file mode 100644 index 37a8ce8c75..0000000000 --- a/tests/test_data/config_dirs/second_one_dir/z.txt +++ /dev/null @@ -1,2 +0,0 @@ -[storage] -path = "this is path from text file" \ No newline at end of file