Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
ostree_dir_repo_test.cc
1 #include <gtest/gtest.h>
2 
3 #include "ostree_dir_repo.h"
4 #include "ostree_ref.h"
5 
6 /* Reject invalid path. */
7 TEST(dir_repo, invalid_path) {
8  OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>("invalid_path");
9  EXPECT_FALSE(src_repo->LooksValid());
10 }
11 
12 /* Reject invalid repo configuration. */
13 TEST(dir_repo, invalid_config) {
14  TemporaryDirectory temp_dir;
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());
19 }
20 
21 /* Reject invalid repo configuration. */
22 TEST(dir_repo, wrong_ini) {
23  TemporaryDirectory temp_dir;
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());
28 }
29 
30 /* Reject bare mode repo. */
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());
34 }
35 
36 /* Verify a local OSTree repository. */
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());
40 }
41 
42 /* Find OSTree ref in local repository. */
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"));
47 }
48 
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"));
52 }
53 
54 /* Find OSTree object in local repository.
55  * Check all valid OSTree object extensions. */
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);
62  std::stringstream s;
63  s << object;
64  EXPECT_EQ(s.str(), std::string("2a/28dac42b76c2015ee3c41cc4183bb8b5c790fd21fa5cfa0802c6e11fd0edbe.dirmeta"));
65 }
66 
67 /* Abort if OSTree object is not found. */
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);
74 }
75 
76 #ifndef __NO_MAIN__
77 int main(int argc, char **argv) {
78  ::testing::InitGoogleTest(&argc, argv);
79  return RUN_ALL_TESTS();
80 }
81 #endif
82 
83 // vim: set tabstop=2 shiftwidth=2 expandtab:
OSTreeObjectMissing
Thrown by GetObject when the object requested is not present in the repository.
Definition: ostree_repo.h:46
TemporaryDirectory
Definition: utils.h:82