aboutsummaryrefslogtreecommitdiffhomepage
path: root/htesting/test_helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'htesting/test_helpers.go')
-rw-r--r--htesting/test_helpers.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/htesting/test_helpers.go b/htesting/test_helpers.go
index 813c9bd04..9a1fe86ef 100644
--- a/htesting/test_helpers.go
+++ b/htesting/test_helpers.go
@@ -16,7 +16,9 @@ package htesting
import (
"math/rand"
"os"
+ "regexp"
"runtime"
+ "strconv"
"strings"
"time"
@@ -103,3 +105,28 @@ func IsGitHubAction() bool {
func SupportsAll() bool {
return IsGitHubAction()
}
+
+// GoMinorVersion returns the minor version of the current Go version,
+// e.g. 16 for Go 1.16.
+func GoMinorVersion() int {
+ return extractMinorVersionFromGoTag(runtime.Version())
+}
+
+var goMinorVersionRe = regexp.MustCompile(`go1.(\d*)`)
+
+func extractMinorVersionFromGoTag(tag string) int {
+ // The tag may be on the form go1.17, go1.17.5 go1.17rc2 -- or just a commit hash.
+ match := goMinorVersionRe.FindStringSubmatch(tag)
+
+ if len(match) == 2 {
+ i, err := strconv.Atoi(match[1])
+ if err != nil {
+ return -1
+ }
+ return i
+ }
+
+ // a commit hash, not useful.
+ return -1
+
+}