mirror of
https://github.com/hanzoai/ca.git
synced 2026-11-03 18:08:27 +00:00
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package version
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestInfo_ParseBuild(t *testing.T) {
|
|
v := Info{Build: "v1.2.114"}
|
|
v.PopulateFromBuild()
|
|
assert.Equal(t, uint(1), v.Major, "Major version")
|
|
assert.Equal(t, uint(2), v.Minor, "MajMinoror version")
|
|
assert.Equal(t, uint(114), v.Commit, "Commit")
|
|
assert.Equal(t, float32(120.114006), v.Float(), "Float")
|
|
|
|
v = Info{Build: "v1.2.114-dirty"}
|
|
v.PopulateFromBuild()
|
|
assert.Equal(t, uint(1), v.Major, "Major version")
|
|
assert.Equal(t, uint(2), v.Minor, "MajMinoror version")
|
|
assert.Equal(t, uint(114), v.Commit, "Commit")
|
|
assert.Equal(t, float32(120.114006), v.Float(), "Float")
|
|
}
|
|
|
|
func TestInfo_GreaterOrEqual(t *testing.T) {
|
|
v01 := Info{0, 1, 3, "", "go1.5", float32(1.3)}
|
|
v02 := Info{0, 2, 3, "", "go1.5", float32(102.3)}
|
|
v10 := Info{1, 0, 30, "", "go1.5", float32(100.30)}
|
|
v12 := Info{1, 2, 31234, "", "go1.5", float32(102.31234)}
|
|
v20 := Info{2, 19, 2312234, "", "go1.5", float32(219.2312234)}
|
|
f := func(v, other Info, expected bool) {
|
|
act := v.GreaterOrEqual(other)
|
|
if act != expected {
|
|
t.Errorf("%v GreaterOrEqual (%v) return wrong result of %v, expecting %v", v, other, act, expected)
|
|
}
|
|
}
|
|
f(v01, v01, true)
|
|
f(v02, v01, true)
|
|
f(v10, v01, true)
|
|
f(v20, v12, true)
|
|
f(v02, v10, false)
|
|
f(v01, v02, false)
|
|
}
|