1 #include <gtest/gtest.h>
3 #include <boost/process.hpp>
5 #include "authenticate.h"
6 #include "crypto/crypto.h"
9 #include "ostree_dir_repo.h"
10 #include "ostree_http_repo.h"
11 #include "ostree_ref.h"
12 #include "test_utils.h"
14 std::string port =
"2443";
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";
25 auto test_ref = src_repo->GetRef(
"master");
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};
31 EXPECT_EQ(authenticate(cert_path.string(), server_creds, push_server), EXIT_SUCCESS);
32 UploadToTreehub(src_repo, push_server,
OSTreeHash(hash), run_mode, 2);
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.";
38 bool push_root_ref_res = PushRootRef(push_server, test_ref);
39 EXPECT_TRUE(push_root_ref_res);
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.";
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";
52 auth[
"ostree"][
"server"] = std::string(
"https://localhost:") + port;
53 Utils::writeFile(temp_dir.Path() /
"auth.json", auth);
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();