This commit is contained in:
Liang Ding 2018-10-28 09:59:23 +08:00
parent 10d8d65d72
commit d4980a0e4d
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
1 changed files with 16 additions and 5 deletions

View File

@ -16,9 +16,10 @@ package util
import ( import (
"runtime" "runtime"
"strconv"
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/go-version"
) )
func TestGetCrossPlatforms(t *testing.T) { func TestGetCrossPlatforms(t *testing.T) {
@ -33,17 +34,27 @@ func TestGetAPIPath(t *testing.T) {
apiPath := Go.GetAPIPath() apiPath := Go.GetAPIPath()
v := runtime.Version()[2:] v := runtime.Version()[2:]
v = v[:3] if 3 < len(v) {
v = v[:4]
verNum, err := strconv.ParseFloat(v, 64) } else {
v = v[:3]
}
ver, err := version.NewVersion(v)
if nil != err { if nil != err {
t.Error(err) t.Error(err)
return return
} }
if verNum >= 1.4 { constraints, err := version.NewConstraint(">= 1.4")
if nil != err {
t.Error(err)
return
}
if constraints.Check(ver) {
if !strings.HasSuffix(apiPath, "src") { if !strings.HasSuffix(apiPath, "src") {
t.Error("api path should end with \"src\"") t.Error("api path should end with \"src\"")