Skip to content

Commit

Permalink
add ToString function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahfa92 committed Jan 18, 2024
1 parent 42dfef3 commit d90ca9e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions utils/dbhelper/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package dbhelper

import (
"fmt"
"strconv"
"strings"
)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions utils/dbhelper/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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") {
Expand Down

0 comments on commit d90ca9e

Please sign in to comment.