✨ Add Random Generator
This commit is contained in:
parent
5c1132e414
commit
1677a692d1
8 changed files with 142 additions and 53 deletions
42
gen_rand_test.go
Normal file
42
gen_rand_test.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package nomino
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUUID(t *testing.T) {
|
||||
st, err := UUID()(nil)
|
||||
assert.NoError(t, err)
|
||||
_, parseErr := uuid.Parse(st)
|
||||
assert.NoError(t, parseErr)
|
||||
}
|
||||
|
||||
type badRead struct{}
|
||||
|
||||
func (badRead) Read([]byte) (int, error) {
|
||||
return 0, errors.New("sorry")
|
||||
}
|
||||
|
||||
func TestUUIDFail(t *testing.T) {
|
||||
uuid.SetRand(badRead{})
|
||||
defer uuid.SetRand(nil)
|
||||
|
||||
_, err := UUID()(nil)
|
||||
assert.Equal(t, errors.New("sorry"), err)
|
||||
}
|
||||
|
||||
func TestRand(t *testing.T) {
|
||||
st, err := Random()(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, st, 8)
|
||||
}
|
||||
|
||||
func TestRandLen(t *testing.T) {
|
||||
st, err := Random(RandomLength(32))(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, st, 32)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue