Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
helpers_test.cc
1 #include <gtest/gtest.h>
2 
3 #include "helpers.h"
4 
5 static boost::filesystem::path test_sysroot;
6 
7 TEST(version, bad_versions) {
8  ASSERT_TRUE(Version("bar") < Version("foo"));
9  ASSERT_TRUE(Version("1.bar") < Version("2foo"));
10  ASSERT_TRUE(Version("1..0") < Version("1.1"));
11  ASSERT_TRUE(Version("1.-1") < Version("1.1"));
12  ASSERT_TRUE(Version("1.*bad #text") < Version("1.1")); // ord('*') < ord('1')
13 }
14 
15 TEST(version, good_versions) {
16  ASSERT_TRUE(Version("1.0.1") < Version("1.0.1.1"));
17  ASSERT_TRUE(Version("1.0.1") < Version("1.0.2"));
18  ASSERT_TRUE(Version("0.9") < Version("1.0.1"));
19  ASSERT_TRUE(Version("1.0.0.0") < Version("1.0.0.1"));
20  ASSERT_TRUE(Version("1") < Version("1.0.0.1"));
21  ASSERT_TRUE(Version("1.9.0") < Version("1.10"));
22 }
23 
24 // Ensure we finalize an install if completed
25 TEST(helpers, lite_client_finalize) {
26  TemporaryDirectory cfg_dir;
27 
28  Config config;
29  config.storage.path = cfg_dir.Path();
30  config.pacman.type = PACKAGE_MANAGER_OSTREE;
31  config.pacman.sysroot = test_sysroot;
32  std::shared_ptr<INvStorage> storage = INvStorage::newStorage(config.storage);
33 
34  Json::Value target_json;
35  target_json["hashes"]["sha256"] = "deadbeef";
36  target_json["custom"]["targetFormat"] = "OSTREE";
37  target_json["length"] = 0;
38  Uptane::Target target("test-finalize", target_json);
39 
40  setenv("OSTREE_HASH", "deadbeef", 1);
41  storage->savePrimaryInstalledVersion(target, InstalledVersionUpdateMode::kPending);
42  ASSERT_TRUE(target.MatchHash(LiteClient(config).primary->getCurrent().hashes()[0]));
43 
44  config = Config(); // Create a new config since LiteClient std::move's it
45  config.storage.path = cfg_dir.Path();
46  config.pacman.type = "ostree";
47  config.pacman.sysroot = test_sysroot;
48 
49  setenv("OSTREE_HASH", "abcd", 1);
50  storage->savePrimaryInstalledVersion(target, InstalledVersionUpdateMode::kPending);
51  ASSERT_FALSE(target.MatchHash(LiteClient(config).primary->getCurrent().hashes()[0]));
52 }
53 
54 #ifndef __NO_MAIN__
55 int main(int argc, char **argv) {
56  ::testing::InitGoogleTest(&argc, argv);
57 
58  if (argc != 2) {
59  std::cerr << "Error: " << argv[0] << " requires the path to an OSTree sysroot.\n";
60  return EXIT_FAILURE;
61  }
62 
63  TemporaryDirectory temp_dir;
64  // Utils::copyDir doesn't work here. Complaints about non existent symlink path
65  int r = system((std::string("cp -r ") + argv[1] + std::string(" ") + temp_dir.PathString()).c_str());
66  if (r != 0) {
67  return -1;
68  }
69  test_sysroot = (temp_dir.Path() / "ostree_repo").string();
70 
71  return RUN_ALL_TESTS();
72 }
73 #endif
LiteClient
Definition: helpers.h:17
Version
Definition: helpers.h:10
Config
Configuration object for an aktualizr instance running on a primary ECU.
Definition: config.h:74
TemporaryDirectory
Definition: utils.h:82
Uptane::Target
Definition: tuf.h:238