File: randomstring_test.go

package info (click to toggle)
golang-github-juju-utils 0.0~git20171220.f38c0b0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,748 kB
  • sloc: makefile: 20
file content (35 lines) | stat: -rw-r--r-- 767 bytes parent folder | download | duplicates (2)
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))
	}
}