https://github.com/cilium/cilium
Raw File
Tip revision: 67190636f1d5a7a443ea0bda585b215e7650dd25 authored by Joe Stringer on 13 February 2023, 08:31:05 UTC
Prepare for version v1.12.7
Tip revision: 6719063
rand_name_test.go
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium

//go:build !privileged_tests

package rand

import (
	"strings"
	"testing"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) {
	TestingT(t)
}

type RandSuite struct{}

var _ = Suite(&RandSuite{})

func (s *RandSuite) TestRandomString(c *C) {
	c.Assert(len(RandomString()), Equals, 12)

	c.Assert(len(RandomStringWithLen(12)), Equals, 12)
	c.Assert(len(RandomStringWithLen(0)), Equals, 0)

	s0 := RandomStringWithPrefix("foo", 12)
	c.Assert(len(s0), Equals, len("foo")+12)
	c.Assert(strings.HasPrefix(s0, "foo"), Equals, true)

	s1 := RandomLowercaseStringWithLen(15)
	c.Assert(len(s1), Equals, 15)
	c.Assert(strings.ToLower(s1), Equals, s1)
}
back to top