Skip to content

Commit

Permalink
SAAS-529 two types of mongo db version check (#730)
Browse files Browse the repository at this point in the history
* SAAS-529 2 types of MongoDB version check

* SAAS-529 2 types of MongoDB version check

* SAAS-529 2 types of MongoDB version check

* SAAS-529 2 types of MongoDB version check

* SAAS-529 2 types of MongoDB version check

* SAAS-529 2 types of MongoDB version check

* SAAS-529 fix new function

* SAAS-529 fix new function

* SAAS-529 remove pmm version check

* SAAS-529 remove pmm version check

* SAAS-529 fix checks

* SAAS-529 fix checks

* SAAS-529 fix checks
  • Loading branch information
adivinho authored May 4, 2021
1 parent a4754fe commit df3f775
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 14 additions & 5 deletions version/parsed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
)

var versionRE = regexp.MustCompile(`^(\d+)\.(\d+)\.(\d+)(.*)$`)
var fetchRest = regexp.MustCompile(`^-(\d+)-?(.*)$`)

// Parsed represents a SemVer-like version information.
type Parsed struct {
Major int
Minor int
Patch int
Rest string
Num int // MMmmpp
Major int
Minor int
Patch int
Rest string
Num int // MMmmpp
NumRest int
}

// Parse parses version information from given string.
Expand All @@ -36,6 +38,13 @@ func Parse(s string) (*Parsed, error) {
return nil, err
}

r := fetchRest.FindStringSubmatch(res.Rest)
if len(r) != 0 {
if res.NumRest, err = strconv.Atoi(r[1]); err != nil {
return nil, err
}
}

res.Num = res.Major*10000 + res.Minor*100 + res.Patch
return res, nil
}
Expand Down
9 changes: 6 additions & 3 deletions version/parsed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func TestParsed(t *testing.T) {
}, {
s: "3.0.0",
p: &Parsed{Major: 3, Minor: 0, Patch: 0, Num: 30000},
}, {
s: "4.0.0-12",
p: &Parsed{Major: 4, Minor: 0, Patch: 0, Rest: "-12", Num: 40000, NumRest: 12},
},
}
for i, expected := range data {
Expand All @@ -57,19 +60,19 @@ func TestParsed(t *testing.T) {
}{
{
s: "5.6.47-87.0-log",
p: &Parsed{Major: 5, Minor: 6, Patch: 47, Rest: "-87.0-log", Num: 50647},
p: &Parsed{Major: 5, Minor: 6, Patch: 47, Rest: "-87.0-log", Num: 50647, NumRest: 87},
}, {
s: "5.6.48-log",
p: &Parsed{Major: 5, Minor: 6, Patch: 48, Rest: "-log", Num: 50648},
}, {
s: "5.7.29-32-log",
p: &Parsed{Major: 5, Minor: 7, Patch: 29, Rest: "-32-log", Num: 50729},
p: &Parsed{Major: 5, Minor: 7, Patch: 29, Rest: "-32-log", Num: 50729, NumRest: 32},
}, {
s: "5.7.30-log",
p: &Parsed{Major: 5, Minor: 7, Patch: 30, Rest: "-log", Num: 50730},
}, {
s: "8.0.19-10",
p: &Parsed{Major: 8, Minor: 0, Patch: 19, Rest: "-10", Num: 80019},
p: &Parsed{Major: 8, Minor: 0, Patch: 19, Rest: "-10", Num: 80019, NumRest: 10},
}, {
s: "8.0.20",
p: &Parsed{Major: 8, Minor: 0, Patch: 20, Rest: "", Num: 80020},
Expand Down

0 comments on commit df3f775

Please sign in to comment.