This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aktualizr-lite: Fix logic for finding latest version
You can't assume the targets will be ordered latest->oldest. This creates a version comparison helper that tries its best to compare things based on the glibc function: http://man7.org/linux/man-pages/man3/strverscmp.3.html Signed-off-by: Andy Doan <andy@foundries.io>
- Loading branch information
Showing
5 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <string> | ||
|
||
#include <string.h> | ||
|
||
struct Version { | ||
std::string raw_ver; | ||
Version(const std::string& version) : raw_ver(std::move(version)) {} | ||
|
||
bool operator<(const Version& other) { return strverscmp(raw_ver.c_str(), other.raw_ver.c_str()) < 0; } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "version.h" | ||
|
||
TEST(version, bad_versions) { | ||
ASSERT_TRUE(Version("bar") < Version("foo")); | ||
ASSERT_TRUE(Version("1.bar") < Version("2foo")); | ||
ASSERT_TRUE(Version("1..0") < Version("1.1")); | ||
ASSERT_TRUE(Version("1.-1") < Version("1.1")); | ||
ASSERT_TRUE(Version("1.*bad #text") < Version("1.1")); // ord('*') < ord('1') | ||
} | ||
|
||
TEST(version, good_versions) { | ||
ASSERT_TRUE(Version("1.0.1") < Version("1.0.1.1")); | ||
ASSERT_TRUE(Version("1.0.1") < Version("1.0.2")); | ||
ASSERT_TRUE(Version("0.9") < Version("1.0.1")); | ||
ASSERT_TRUE(Version("1.0.0.0") < Version("1.0.0.1")); | ||
ASSERT_TRUE(Version("1") < Version("1.0.0.1")); | ||
ASSERT_TRUE(Version("1.9.0") < Version("1.10")); | ||
} | ||
|
||
#ifndef __NO_MAIN__ | ||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
||
return RUN_ALL_TESTS(); | ||
} | ||
#endif |