🏗️ move make sub-cmd to sub-dir
This commit is contained in:
13
pkg/tool/random/str.go
Normal file
13
pkg/tool/random/str.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package random
|
||||
|
||||
import "math/rand"
|
||||
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
func RandomString(length int) string {
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = charset[rand.Intn(len(charset))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
26
pkg/tool/random/str_test.go
Normal file
26
pkg/tool/random/str_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package random_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"yizhisec.com/hsv2/forge/pkg/tool/random"
|
||||
)
|
||||
|
||||
func TestRandomString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string // description of this test case
|
||||
// Named input parameters for target function.
|
||||
length int
|
||||
want string
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := random.RandomString(tt.length)
|
||||
// TODO: update the condition below to compare got with tt.want.
|
||||
if true {
|
||||
t.Errorf("RandomString() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user