mirror of
https://github.com/MontFerret/ferret.git
synced 2025-11-27 22:08:15 +02:00
stdlib.strings
Added string functions to standard library
This commit is contained in:
49
pkg/stdlib/strings/random_test.go
Normal file
49
pkg/stdlib/strings/random_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package strings_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||||
"github.com/MontFerret/ferret/pkg/stdlib/strings"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRandomToken(t *testing.T) {
|
||||
Convey("When args are not passed", t, func() {
|
||||
Convey("It should return an error", func() {
|
||||
var err error
|
||||
_, err = strings.RandomToken(context.Background())
|
||||
|
||||
So(err, ShouldBeError)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Convey("When args are invalid", t, func() {
|
||||
Convey("It should return an error", func() {
|
||||
var err error
|
||||
_, err = strings.RandomToken(context.Background(), values.NewString("foo"))
|
||||
|
||||
So(err, ShouldBeError)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Should generate random string", t, func() {
|
||||
str1, _ := strings.RandomToken(
|
||||
context.Background(),
|
||||
values.NewInt(8),
|
||||
)
|
||||
|
||||
So(str1, ShouldHaveLength, 8)
|
||||
|
||||
str2, _ := strings.RandomToken(
|
||||
context.Background(),
|
||||
values.NewInt(8),
|
||||
)
|
||||
|
||||
So(str2, ShouldHaveLength, 8)
|
||||
|
||||
So(str1, ShouldNotEqual, str2)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user