parent
3ed1a5dc43
commit
f453b3e918
@ -0,0 +1,27 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteVersionLock(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 清理残余文件
|
||||
if _, err := os.Stat("version.lock"); !os.IsNotExist(err) {
|
||||
err = os.Remove("version.lock")
|
||||
asserts.NoError(err)
|
||||
}
|
||||
|
||||
err := WriteVersionLock()
|
||||
defer func() { err = os.Remove("version.lock") }()
|
||||
writtenVersion, err := ioutil.ReadFile("version.lock")
|
||||
|
||||
// 写入的版本应与当前版本相同
|
||||
asserts.NoError(err)
|
||||
asserts.Equal(string(writtenVersion), BackendVersion)
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRandStringRunes(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 0 长度字符
|
||||
randStr := RandStringRunes(0)
|
||||
asserts.Len(randStr, 0)
|
||||
|
||||
// 16 长度字符
|
||||
randStr = RandStringRunes(16)
|
||||
asserts.Len(randStr, 16)
|
||||
|
||||
// 32 长度字符
|
||||
randStr = RandStringRunes(32)
|
||||
asserts.Len(randStr, 32)
|
||||
|
||||
//相同长度字符
|
||||
sameLenStr1 := RandStringRunes(32)
|
||||
sameLenStr2 := RandStringRunes(32)
|
||||
asserts.NotEqual(sameLenStr1, sameLenStr2)
|
||||
}
|
Loading…
Reference in new issue