Fix version string check to allow properly tagged betas
This commit is contained in:
parent
d74377350b
commit
353689857e
|
@ -49,15 +49,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Version = "unknown-dev"
|
Version = "unknown-dev"
|
||||||
Codename = "Copper Cockroach"
|
Codename = "Copper Cockroach"
|
||||||
BuildStamp = "0"
|
BuildStamp = "0"
|
||||||
BuildDate time.Time
|
BuildDate time.Time
|
||||||
BuildHost = "unknown"
|
BuildHost = "unknown"
|
||||||
BuildUser = "unknown"
|
BuildUser = "unknown"
|
||||||
IsRelease bool
|
IsRelease bool
|
||||||
IsBeta bool
|
IsBeta bool
|
||||||
LongVersion string
|
LongVersion string
|
||||||
|
allowedVersionExp = regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z0-9]+)*(\.\d+)*(\+\d+-g[0-9a-f]+)?(-dirty)?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -89,9 +90,8 @@ const (
|
||||||
func init() {
|
func init() {
|
||||||
if Version != "unknown-dev" {
|
if Version != "unknown-dev" {
|
||||||
// If not a generic dev build, version string should come from git describe
|
// If not a generic dev build, version string should come from git describe
|
||||||
exp := regexp.MustCompile(`^v\d+\.\d+\.\d+(-[a-z0-9]+)*(\+\d+-g[0-9a-f]+)?(-dirty)?$`)
|
if !allowedVersionExp.MatchString(Version) {
|
||||||
if !exp.MatchString(Version) {
|
l.Fatalf("Invalid version string %q;\n\tdoes not match regexp %v", Version, allowedVersionExp)
|
||||||
l.Fatalf("Invalid version string %q;\n\tdoes not match regexp %v", Version, exp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,3 +175,29 @@ func TestShortIDCheck(t *testing.T) {
|
||||||
t.Error("Should have gotten an error")
|
t.Error("Should have gotten an error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAllowedVersions(t *testing.T) {
|
||||||
|
testcases := []struct {
|
||||||
|
ver string
|
||||||
|
allowed bool
|
||||||
|
}{
|
||||||
|
{"v0.13.0", true},
|
||||||
|
{"v0.12.11+22-gabcdef0", true},
|
||||||
|
{"v0.13.0-beta0", true},
|
||||||
|
{"v0.13.0-beta47", true},
|
||||||
|
{"v0.13.0-beta47+1-gabcdef0", true},
|
||||||
|
{"v0.13.0-beta.0", true},
|
||||||
|
{"v0.13.0-beta.47", true},
|
||||||
|
{"v0.13.0-beta.0+1-gabcdef0", true},
|
||||||
|
{"v0.13.0-beta.47+1-gabcdef0", true},
|
||||||
|
{"v0.13.0-some-weird-but-allowed-tag", true},
|
||||||
|
{"v0.13.0-not.allowed.to.do.this", false},
|
||||||
|
{"v0.13.0+not.allowed.to.do.this", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, c := range testcases {
|
||||||
|
if allowed := allowedVersionExp.MatchString(c.ver); allowed != c.allowed {
|
||||||
|
t.Errorf("%d: incorrect result %v != %v for %q", i, allowed, c.allowed, c.ver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue