diff options
| author | Simon Johnsson <simon.johnsson@canonical.com> | 2025-09-26 18:18:42 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-09-26 16:18:42 +0000 |
| commit | 66962bee233b617e4a9ce436f9b26875511b35e6 (patch) | |
| tree | eb72d44c499404fd46c04119e7e5fb214f7833f2 /test | |
| parent | 3c9399e643a07074d47c9bceca88e8d43ff55d36 (diff) | |
History Command and Parsing
Diffstat (limited to 'test')
| -rwxr-xr-x | test/integration/test-history | 30 | ||||
| -rw-r--r-- | test/libapt/history_parse_test.cc | 113 |
2 files changed, 143 insertions, 0 deletions
diff --git a/test/integration/test-history b/test/integration/test-history index 47829e162..34489fce6 100755 --- a/test/integration/test-history +++ b/test/integration/test-history @@ -38,3 +38,33 @@ Commandline: dummy Comment: A test comment Install: pkg2:amd64 (1) End-Date: dummy" cathistory + +normalizedinfo() { + apt history-info 0 | sed -E \ + -e 's/^( *-?Start time *: ).*/\1dummy/' \ + -e 's/^( *-?End time *: ).*/\1dummy/' \ + -e 's|^( *-?Command line *: ).*|\1dummy|' +} + +testsuccessequal "Transaction ID: 0 +Start time: dummy +End time: dummy +Requested by: +Command line: dummy +Packages changed: + Install pkg1:amd64 (1) +" normalizedinfo + +# replace aribtrary command line and date with "dummy". +normalizedlist() { + apt history-list | sed -E 's/^([0-9]+)[[:space:]]+'\ +'[^[:space:]]+[[:space:]]+'\ +'[0-9]{4}-[0-9]{2}-[0-9]{2}[[:space:]]+'\ +'[0-9]{2}:[0-9]{2}:[0-9]{2}/'\ +'\1 dummy dummy /' +} + +testsuccessequal "ID Command line Date and Time Action Changes + +0 dummy dummy Install 1 +1 dummy dummy Install 1 " normalizedlist diff --git a/test/libapt/history_parse_test.cc b/test/libapt/history_parse_test.cc new file mode 100644 index 000000000..526e1573f --- /dev/null +++ b/test/libapt/history_parse_test.cc @@ -0,0 +1,113 @@ +#include <config.h> + +#include <apt-pkg/configuration.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/history.h> +#include <apt-pkg/indexcopy.h> +#include <apt-pkg/tagfile.h> + +#include "common.h" + +#include "file-helpers.h" + +using namespace APT::History; + +TEST(HistoryParseTest, SectionToEntry) +{ + FileFd fd; + const char *entry_section = + "Start-Date: 2025-09-01 15:22:56\n" + "Commandline: apt install rust-coreutils\n" + "Requested-By: user (1000)\n" + "Error: An error occurred\n" + "Comment: This is a comment\n" + "Install: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "End-Date: 2025-09-01 15:22:57"; + + openTemporaryFile("packagesection", fd, entry_section); + + pkgTagFile tfile(&fd); + pkgTagSection section; + ASSERT_TRUE(tfile.Step(section)); + + Entry entry = ParseSection(section); + EXPECT_EQ("2025-09-01 15:22:56", entry.startDate); + EXPECT_EQ("2025-09-01 15:22:57", entry.endDate); + EXPECT_EQ("apt install rust-coreutils", entry.cmdLine); + EXPECT_EQ("user (1000)", entry.requestingUser); + EXPECT_EQ("An error occurred", entry.error); + EXPECT_EQ("This is a comment", entry.comment); + EXPECT_EQ("rust-coreutils:amd64", entry.changeMap[Kind::Install][0].package); + EXPECT_EQ("0.1.0+git20250813.4af2a84-0ubuntu2", entry.changeMap[Kind::Install][0].currentVersion); +} + +TEST(HistoryParseTest, EmptyOptionalFields) +{ + FileFd fd; + const char *entry_section = + "Start-Date: 2025-09-01 15:22:56\n" + "Commandline: apt install rust-coreutils\n" + "Requested-By: user (1000)\n" + "Install: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "End-Date: 2025-09-01 15:22:57"; + openTemporaryFile("packagesection", fd, entry_section); + pkgTagFile tfile(&fd); + pkgTagSection section; + ASSERT_TRUE(tfile.Step(section)); + + Entry entry = ParseSection(section); + EXPECT_EQ("", entry.error); + EXPECT_EQ("", entry.comment); +} + +TEST(HistoryParseTest, MultipleActions) +{ + FileFd fd; + const char *entry_section = + "Start-Date: 2025-09-01 15:22:56\n" + "Commandline: apt install rust-coreutils\n" + "Requested-By: user (1000)\n" + "Error: An error occurred\n" + "Comment: This is a comment\n" + "Install: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "Remove: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "Downgrade: rust-coreutils:amd64 (0.1.0, 0.0.0)\n" + "Reinstall: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "Upgrade: rust-coreutils:amd64 (0.1.0, 0.2.0)\n" + "Purge: rust-coreutils:amd64 (0.1.0+git20250813.4af2a84-0ubuntu2)\n" + "End-Date: 2025-09-01 15:22:57"; + + openTemporaryFile("packagesection", fd, entry_section); + + pkgTagFile tfile(&fd); + pkgTagSection section; + ASSERT_TRUE(tfile.Step(section)); + + Entry entry = ParseSection(section); + Change installChange = entry.changeMap[Kind::Install][0]; + Change removeChange = entry.changeMap[Kind::Remove][0]; + Change downgradeChange = entry.changeMap[Kind::Downgrade][0]; + Change reinstallChange = entry.changeMap[Kind::Reinstall][0]; + Change upgradeChange = entry.changeMap[Kind::Upgrade][0]; + Change purgeChange = entry.changeMap[Kind::Purge][0]; + + EXPECT_EQ("rust-coreutils:amd64", installChange.package); + EXPECT_EQ("0.1.0+git20250813.4af2a84-0ubuntu2", installChange.currentVersion); + + EXPECT_EQ("rust-coreutils:amd64", removeChange.package); + EXPECT_EQ("0.1.0+git20250813.4af2a84-0ubuntu2", removeChange.currentVersion); + + EXPECT_EQ("rust-coreutils:amd64", downgradeChange.package); + EXPECT_EQ("0.1.0", downgradeChange.currentVersion); + EXPECT_EQ("0.0.0", downgradeChange.candidateVersion); + + EXPECT_EQ("rust-coreutils:amd64", reinstallChange.package); + EXPECT_EQ("0.1.0+git20250813.4af2a84-0ubuntu2", reinstallChange.currentVersion); + + EXPECT_EQ("rust-coreutils:amd64", upgradeChange.package); + EXPECT_EQ("0.1.0", upgradeChange.currentVersion); + EXPECT_EQ("0.2.0", upgradeChange.candidateVersion); + + EXPECT_EQ("rust-coreutils:amd64", purgeChange.package); + EXPECT_EQ("0.1.0+git20250813.4af2a84-0ubuntu2", purgeChange.currentVersion); +} |
