go-zero/tools/goctl/internal/version/version_test.go
anqiansong 8829c31c0d
Feature goctl error wrap (#995)
* Add `Wrap` in file errorx.go

* Wrap error with `GoctlError`

* format code

* Refactor package `env` to `version`

* Refactor package `IsVersionGatherThan`

* fix typo

Co-authored-by: anqiansong <anqiansong@bytedance.com>
2021-09-05 21:57:44 +08:00

34 lines
873 B
Go

package version
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_convertVersion(t *testing.T) {
number, tag := convertVersion("1.1.10")
assert.Equal(t, 1.110, number)
assert.Equal(t, "", tag)
number, tag = convertVersion("0.1.11")
assert.Equal(t, 0.111, number)
assert.Equal(t, "", tag)
number, tag = convertVersion("1.11-pre")
assert.Equal(t, 1.11, number)
assert.Equal(t, "pre", tag)
number, tag = convertVersion("1.11-beta-v1")
assert.Equal(t, 1.11, number)
assert.Equal(t, "betav1", tag)
}
func Test_IsVersionGatherThan(t *testing.T) {
assert.False(t, IsVersionGreaterThan("0.11", "1.1"))
assert.True(t, IsVersionGreaterThan("0.112", "0.1"))
assert.True(t, IsVersionGreaterThan("1.1.10", "1.0.111"))
assert.True(t, IsVersionGreaterThan("1.1.10", "1.1.10-pre"))
assert.True(t, IsVersionGreaterThan("1.1.11-pre", "1.1.10"))
}