Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
deploy_test.cc
1 #include <gtest/gtest.h>
2 
3 #include <boost/process.hpp>
4 
5 #include "authenticate.h"
6 #include "crypto/crypto.h"
7 #include "deploy.h"
8 #include "garage_common.h"
9 #include "ostree_dir_repo.h"
10 #include "ostree_http_repo.h"
11 #include "ostree_ref.h"
12 #include "test_utils.h"
13 
14 std::string port = "2443";
15 TemporaryDirectory temp_dir;
16 
17 /* Fetch OSTree objects from source repository and push to destination repository.
18  * Parse OSTree object to identify child objects. */
19 TEST(deploy, UploadToTreehub) {
20  OSTreeRepo::ptr src_repo = std::make_shared<OSTreeDirRepo>("tests/sota_tools/repo");
21  boost::filesystem::path filepath = (temp_dir.Path() / "auth.json").string();
22  boost::filesystem::path cert_path = "tests/fake_http_server/server.crt";
23  auto server_creds = ServerCredentials(filepath);
24  auto run_mode = RunMode::kDefault;
25  auto test_ref = src_repo->GetRef("master");
26 
27  const uint8_t hash[32] = {0x16, 0xef, 0x2f, 0x26, 0x29, 0xdc, 0x92, 0x63, 0xfd, 0xf3, 0xc0,
28  0xf0, 0x32, 0x56, 0x3a, 0x2d, 0x75, 0x76, 0x23, 0xbb, 0xc1, 0x1c,
29  0xf9, 0x9d, 0xf2, 0x5c, 0x3c, 0x3f, 0x25, 0x8d, 0xcc, 0xbe};
30  TreehubServer push_server;
31  EXPECT_EQ(authenticate(cert_path.string(), server_creds, push_server), EXIT_SUCCESS);
32  UploadToTreehub(src_repo, push_server, OSTreeHash(hash), run_mode, 2);
33 
34  int result = system(
35  (std::string("diff -r ") + (temp_dir.Path() / "objects/").string() + " tests/sota_tools/repo/objects/").c_str());
36  EXPECT_EQ(result, 0) << "Diff between the source repo objects and the destination repo objects is nonzero.";
37 
38  bool push_root_ref_res = PushRootRef(push_server, test_ref);
39  EXPECT_TRUE(push_root_ref_res);
40 
41  result =
42  system((std::string("diff -r ") + (temp_dir.Path() / "refs/").string() + " tests/sota_tools/repo/refs/").c_str());
43  EXPECT_EQ(result, 0) << "Diff between the source repo refs and the destination repos refs is nonzero.";
44 }
45 
46 #ifndef __NO_MAIN__
47 int main(int argc, char **argv) {
48  ::testing::InitGoogleTest(&argc, argv);
49  port = TestUtils::getFreePort();
50  std::string server = "tests/sota_tools/treehub_server.py";
51  Json::Value auth;
52  auth["ostree"]["server"] = std::string("https://localhost:") + port;
53  Utils::writeFile(temp_dir.Path() / "auth.json", auth);
54 
55  boost::process::child server_process(server, std::string("-p"), port, std::string("-d"), temp_dir.PathString(),
56  std::string("--tls"));
57  TestUtils::waitForServer("https://localhost:" + port + "/");
58  return RUN_ALL_TESTS();
59 }
60 #endif
61 
62 // vim: set tabstop=2 shiftwidth=2 expandtab:
OSTreeHash
Definition: ostree_hash.h:10
ServerCredentials
Definition: server_credentials.h:25
TreehubServer
Definition: treehub_server.h:11
TemporaryDirectory
Definition: utils.h:82
result
Results of libaktualizr API calls.
Definition: results.h:12
garage_common.h
RunMode::kDefault
@ kDefault
Default operation.