github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/strings/random_test.go (about)

     1  package strings_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	. "github.com/smartystreets/goconvey/convey"
     8  
     9  	"github.com/MontFerret/ferret/pkg/runtime/values"
    10  	"github.com/MontFerret/ferret/pkg/stdlib/strings"
    11  )
    12  
    13  func TestRandomToken(t *testing.T) {
    14  	Convey("When args are not passed", t, func() {
    15  		Convey("It should return an error", func() {
    16  			var err error
    17  			_, err = strings.RandomToken(context.Background())
    18  
    19  			So(err, ShouldBeError)
    20  
    21  		})
    22  	})
    23  
    24  	Convey("When args are invalid", t, func() {
    25  		Convey("It should return an error", func() {
    26  			var err error
    27  			_, err = strings.RandomToken(context.Background(), values.NewString("foo"))
    28  
    29  			So(err, ShouldBeError)
    30  
    31  		})
    32  	})
    33  
    34  	Convey("Should generate random string", t, func() {
    35  		str1, _ := strings.RandomToken(
    36  			context.Background(),
    37  			values.NewInt(8),
    38  		)
    39  
    40  		So(str1, ShouldHaveLength, 8)
    41  
    42  		str2, _ := strings.RandomToken(
    43  			context.Background(),
    44  			values.NewInt(8),
    45  		)
    46  
    47  		So(str2, ShouldHaveLength, 8)
    48  
    49  		So(str1, ShouldNotEqual, str2)
    50  	})
    51  }