From d90ca9eb4df84893b9e371b71aafbafbfd3098cf Mon Sep 17 00:00:00 2001 From: ahfa92 Date: Thu, 18 Jan 2024 08:34:52 +0100 Subject: [PATCH] add ToString function --- utils/dbhelper/version.go | 5 +++++ utils/dbhelper/version_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/utils/dbhelper/version.go b/utils/dbhelper/version.go index d8882a6c3..67172c5ee 100644 --- a/utils/dbhelper/version.go +++ b/utils/dbhelper/version.go @@ -10,6 +10,7 @@ package dbhelper import ( + "fmt" "strconv" "strings" ) @@ -75,6 +76,10 @@ func (mv *MySQLVersion) ToInt(tokens int) int { return (mv.Major * 1000000) + (mv.Minor * 1000) + mv.Release } +func (mv *MySQLVersion) ToString() string { + return fmt.Sprintf("%d.%d.%d", mv.Major, mv.Minor, mv.Release) +} + func (mv *MySQLVersion) Greater(vstring string) bool { v, tokens := NewMySQLVersion(vstring, mv.Flavor) return mv.ToInt(tokens) > v.ToInt(tokens) diff --git a/utils/dbhelper/version_test.go b/utils/dbhelper/version_test.go index 1bd242df5..17743e9b9 100644 --- a/utils/dbhelper/version_test.go +++ b/utils/dbhelper/version_test.go @@ -18,7 +18,7 @@ func TestMySQLVersion(t *testing.T) { tstring, cstring = "8.0.28", "" mv, _ := NewMySQLVersion(tstring, cstring) - t.Logf("Created Version of %s with version %d.%d.%d", mv.Flavor, mv.Major, mv.Minor, mv.Release) + t.Logf("Created Version of %s with version %s", mv.Flavor, mv.ToString()) if mv.Equal("8.0.28") { t.Log("Equal(8.0.28) is true (Correct)") @@ -135,12 +135,12 @@ func TestMariaDBVersion(t *testing.T) { tstring, cstring = "10.11.6-MariaDB-1:10.11.6+maria~ubu2204-log", "MariaDB" mv, _ := NewMySQLVersion(tstring, cstring) - t.Logf("Created Version of %s with version %d.%d.%d", mv.Flavor, mv.Major, mv.Minor, mv.Release) + t.Logf("Created Version of %s with version %s", mv.Flavor, mv.ToString()) - if mv.Equal("10.11.6") { - t.Log("Equal(10.11.6) is true (Correct)") + if mv.Equal(mv.ToString()) { + t.Log("Equal(mv.ToString()) is true (Correct)") } else { - t.Error("Equal(10.11.6) is false (Incorrect)") + t.Error("Equal(mv.ToString()) is false (Incorrect)") } if mv.Equal("10.11") {