Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Test for autoclean aktualizr callback
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Bonnans <[email protected]>
  • Loading branch information
lbonn committed Aug 23, 2019
1 parent d75d19a commit 784f4bb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
57 changes: 57 additions & 0 deletions src/libaktualizr/primary/aktualizr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "config/config.h"
#include "httpfake.h"
#include "primary/aktualizr.h"
#include "primary/aktualizr_helpers.h"
#include "primary/events.h"
#include "primary/sotauptaneclient.h"
#include "uptane_test_common.h"
Expand Down Expand Up @@ -1362,6 +1363,62 @@ TEST(Aktualizr, DownloadListRemove) {
EXPECT_EQ(targets.size(), 0);
}

TEST(Aktualizr, TargetAutoremove) {
TemporaryDirectory temp_dir;
const boost::filesystem::path local_metadir = temp_dir / "metadir";
Utils::createDirectories(local_metadir, S_IRWXU);
auto http = std::make_shared<HttpFake>(temp_dir.Path(), "", local_metadir / "repo");

UptaneRepo repo{local_metadir, "2021-07-04T16:33:27Z", "id0"};
repo.generateRepo(KeyType::kED25519);
const std::string hwid = "primary_hw";
repo.addImage(fake_meta_dir / "fake_meta/primary_firmware.txt", "primary_firmware.txt", hwid, "", {});
repo.addTarget("primary_firmware.txt", hwid, "CA:FE:A6:D2:84:9D", "");
repo.signTargets();

Config conf = UptaneTestCommon::makeTestConfig(temp_dir, http->tls_server);
auto storage = INvStorage::newStorage(conf.storage);
UptaneTestCommon::TestAktualizr aktualizr(conf, storage, http);

// attach the autoclean handler
boost::signals2::connection ac_conn =
aktualizr.SetSignalHandler(std::bind(targets_autoclean_cb, std::ref(aktualizr), std::placeholders::_1));
aktualizr.Initialize();

{
result::UpdateCheck update_result = aktualizr.CheckUpdates().get();
aktualizr.Download(update_result.updates).get();

EXPECT_EQ(aktualizr.GetStoredTargets().size(), 1);

result::Install install_result = aktualizr.Install(update_result.updates).get();
EXPECT_TRUE(install_result.dev_report.success);

EXPECT_EQ(aktualizr.GetStoredTargets().size(), 1);
}

// second install
repo.emptyTargets();
repo.addImage(fake_meta_dir / "fake_meta/dummy_firmware.txt", "dummy_firmware.txt", hwid, "", {});
repo.addTarget("dummy_firmware.txt", hwid, "CA:FE:A6:D2:84:9D", "");
repo.signTargets();

{
result::UpdateCheck update_result = aktualizr.CheckUpdates().get();
aktualizr.Download(update_result.updates).get();

EXPECT_EQ(aktualizr.GetStoredTargets().size(), 2);

result::Install install_result = aktualizr.Install(update_result.updates).get();
EXPECT_TRUE(install_result.dev_report.success);

// first target was removed
std::vector<Uptane::Target> targets = aktualizr.GetStoredTargets();
ASSERT_EQ(targets.size(), 1);
EXPECT_EQ(targets[0].filename(), "dummy_firmware.txt");
}
}

/*
* Initialize -> Install -> nothing to install.
*
Expand Down
3 changes: 0 additions & 3 deletions tests/metafake.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include "utilities/utils.h"
#include "uptane_repo.h"

enum BackupList {
};

class MetaFake {
public:
MetaFake(const boost::filesystem::path &meta_dir_in)
Expand Down

0 comments on commit 784f4bb

Please sign in to comment.