提交 02c79940 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Add test cases for password util

上级 188d9b8d
......@@ -5,7 +5,12 @@ import (
"time"
)
// GeneratePassword generates a password with the specific length
func GeneratePassword(length int) string {
if length <= 0 {
return ""
}
rand.Seed(time.Now().UnixNano())
digits := "0123456789"
specials := "~=+%^*/()[]{}/!@#$?|"
......
package util
import (
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Password util test", func() {
var (
ctrl *gomock.Controller
length int
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
length = 3
})
AfterEach(func() {
ctrl.Finish()
})
Context("basic test", func() {
It("password length", func() {
pass := GeneratePassword(length)
Expect(len(pass)).To(Equal(length))
})
It("Different length", func() {
length = 6
pass := GeneratePassword(length)
Expect(len(pass)).To(Equal(length))
})
It("Negative length", func() {
length = -1
pass := GeneratePassword(length)
Expect(len(pass)).To(Equal(0))
})
It("Zero length", func() {
length = 0
pass := GeneratePassword(length)
Expect(len(pass)).To(Equal(length))
})
})
})
package util
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestUtils(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "jcli utils test")
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册