Skip to content

Commit

Permalink
fix: version matcher with 4 digits jdk version (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
qiaoleiatms and actions-user authored Sep 1, 2023
1 parent 5477750 commit 8e13f56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion springboot/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"github.com/onsi/gomega/types"
"golang.org/x/mod/semver"
"regexp"
"strings"
)

var (
legacyJdkVersions versions = []string{"1.5", "1.6", "1.7", "1.8"}
validVersionRegex = regexp.MustCompile(`^[^\\.]+(\.[^\\.]+){0,2}`)
)

type versions []string
Expand Down Expand Up @@ -70,7 +72,8 @@ func GreatThan(versionA, versionB string) bool {
}

func SanitizeVersion(version string) string {
return strings.ReplaceAll(CleanOutput(version), "_", "-")
cleaned := strings.ReplaceAll(CleanOutput(version), "_", "-")
return validVersionRegex.FindString(cleaned)
}

func IsValidJdkVersion(version string) bool {
Expand Down
17 changes: 12 additions & 5 deletions springboot/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,39 @@ var _ = Describe("test version matcher", func() {
It("should as expected", func() {
m := versionMatcher{expect: "1.8"}

Expect(m.Match("1.8.0")).Should(BeTrue())
Expect("1.8.0").Should(m)
})
})

When("version with prerelease matched", func() {
It("should as expected", func() {
m := versionMatcher{expect: "1.8"}

Expect(m.Match("1.8.231_ea")).Should(BeTrue())
Expect("1.8.231_ea").Should(m)
})
})

When("java 8 version matched", func() {
It("should as expected", func() {
m := versionMatcher{expect: "1.8"}

Expect(m.Match("8")).Should(BeTrue())
Expect("8").Should(m)
})
})

When("java 11 version with 4 digits matched", func() {
It("should as expected", func() {
m := versionMatcher{expect: "11"}

Expect("11.0.21.1").Should(m)
})
})

When("invalid version matched", func() {
It("should not matched", func() {
m := versionMatcher{expect: "1.8"}

Expect(m.Match("a.b.c")).Should(BeFalse())
Expect("a.b.c").ShouldNot(m)
})
})

Expand Down Expand Up @@ -66,7 +74,6 @@ var _ = Describe("test version matcher", func() {
Expect(IsValidJdkVersion("a.b.c.d")).Should(BeFalse())
Expect(IsValidJdkVersion("1.b.c.d")).Should(BeFalse())
Expect(IsValidJdkVersion("1.7.c.d")).Should(BeFalse())
Expect(IsValidJdkVersion("1.7.6.d")).Should(BeFalse())
Expect(IsValidJdkVersion("1.7.6-d")).Should(BeTrue())
Expect(IsValidJdkVersion("1.7.6_d")).Should(BeTrue())
})
Expand Down

0 comments on commit 8e13f56

Please sign in to comment.