1 #include <gtest/gtest.h>
3 #include "ostree_dir_repo.h"
4 #include "ostree_ref.h"
7 TEST(dir_repo, invalid_path) {
8 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"invalid_path");
9 EXPECT_FALSE(src_repo->LooksValid());
13 TEST(dir_repo, invalid_config) {
15 Utils::copyDir(
"tests/sota_tools/repo", temp_dir.Path());
16 Utils::writeFile(temp_dir.Path() /
"repo/config", std::string(
"123"));
17 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(temp_dir.Path() /
"repo");
18 EXPECT_FALSE(src_repo->LooksValid());
22 TEST(dir_repo, wrong_ini) {
24 Utils::copyDir(
"tests/sota_tools/repo", temp_dir.Path());
25 Utils::writeFile(temp_dir.Path() /
"repo/config", std::string(
"[core]"));
26 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(temp_dir.Path() /
"repo");
27 EXPECT_FALSE(src_repo->LooksValid());
31 TEST(dir_repo, bare_mode) {
32 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/bare-repo");
33 EXPECT_FALSE(src_repo->LooksValid());
37 TEST(dir_repo, good_repo) {
38 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/repo");
39 EXPECT_TRUE(src_repo->LooksValid());
43 TEST(dir_repo, getRef) {
44 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/repo");
45 EXPECT_EQ(src_repo->GetRef(
"master").GetHash().string(),
46 std::string(
"16ef2f2629dc9263fdf3c0f032563a2d757623bbc11cf99df25c3c3f258dccbe"));
49 TEST(dir_repo, root) {
50 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/repo");
51 EXPECT_EQ(src_repo->root(), std::string(
"tests/sota_tools/repo"));
56 TEST(dir_repo, GetObject) {
57 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/repo");
58 const uint8_t hash[32] = {0x2a, 0x28, 0xda, 0xc4, 0x2b, 0x76, 0xc2, 0x01, 0x5e, 0xe3, 0xc4,
59 0x1c, 0xc4, 0x18, 0x3b, 0xb8, 0xb5, 0xc7, 0x90, 0xfd, 0x21, 0xfa,
60 0x5c, 0xfa, 0x08, 0x02, 0xc6, 0xe1, 0x1f, 0xd0, 0xed, 0xbe};
61 auto object = src_repo->GetObject(hash, OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_META);
64 EXPECT_EQ(s.str(), std::string(
"2a/28dac42b76c2015ee3c41cc4183bb8b5c790fd21fa5cfa0802c6e11fd0edbe.dirmeta"));
68 TEST(dir_repo, GetObject_Missing) {
69 OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>(
"tests/sota_tools/repo");
70 const uint8_t hash[32] = {0x01, 0x28, 0xda, 0xc4, 0x2b, 0x76, 0xc2, 0x01, 0x5e, 0xe3, 0xc4,
71 0x1c, 0xc4, 0x18, 0x3b, 0xb8, 0xb5, 0xc7, 0x90, 0xfd, 0x21, 0xfa,
72 0x5c, 0xfa, 0x08, 0x02, 0xc6, 0xe1, 0x1f, 0xd0, 0xed, 0xbe};
73 EXPECT_THROW(src_repo->GetObject(hash, OstreeObjectType::OSTREE_OBJECT_TYPE_DIR_META),
OSTreeObjectMissing);
77 int main(
int argc,
char **argv) {
78 ::testing::InitGoogleTest(&argc, argv);
79 return RUN_ALL_TESTS();