未验证 提交 520889fa 编写于 作者: Y Yanjun Shi 提交者: GitHub

Merge pull request #113 from LinuxSuRen/test/util-password

Add test cases for password util
...@@ -29,5 +29,17 @@ pipeline { ...@@ -29,5 +29,17 @@ pipeline {
} }
} }
} }
stage('Test') {
steps {
container('golang') {
sh label: 'go test', script: '''
go test ./util/... -v
go test ./client/... -v
go test ./app/... -v
'''
}
}
}
} }
} }
\ No newline at end of file
...@@ -5,7 +5,12 @@ import ( ...@@ -5,7 +5,12 @@ import (
"time" "time"
) )
// GeneratePassword generates a password with the specific length
func GeneratePassword(length int) string { func GeneratePassword(length int) string {
if length <= 0 {
return ""
}
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
digits := "0123456789" digits := "0123456789"
specials := "~=+%^*/()[]{}/!@#$?|" 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.
先完成此消息的编辑!
想要评论请 注册