1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
// Copyright 2015 Canonical Ltd.
// Copyright 2015 Cloudbase Solutions SRL
// Licensed under the LGPLv3, see LICENCE file for details.
package utils_test
import (
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"github.com/juju/utils"
gc "gopkg.in/check.v1"
)
type randomStringSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&randomStringSuite{})
var (
validChars = []rune("thisissorandom")
length = 7
)
func (randomStringSuite) TestLength(c *gc.C) {
s := utils.RandomString(length, validChars)
c.Assert(s, gc.HasLen, length)
}
func (randomStringSuite) TestContentInValidRunes(c *gc.C) {
s := utils.RandomString(length, validChars)
for _, char := range s {
c.Assert(string(validChars), jc.Contains, string(char))
}
}
|