Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fdb5cefa
Commit
fdb5cefa
authored
Jul 22, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix unit test breakage by adding seed method to util/rand
parent
a558edf0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
tokens_controller_test.go
pkg/serviceaccount/tokens_controller_test.go
+2
-2
rand.go
pkg/util/rand/rand.go
+11
-3
No files found.
pkg/serviceaccount/tokens_controller_test.go
View file @
fdb5cefa
...
...
@@ -17,13 +17,13 @@ limitations under the License.
package
serviceaccount
import
(
"math/rand"
"reflect"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/testclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
utilrand
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/rand"
)
type
testGenerator
struct
{
...
...
@@ -372,7 +372,7 @@ func TestTokenCreation(t *testing.T) {
for
k
,
tc
:=
range
testcases
{
// Re-seed to reset name generation
rand
.
Seed
(
1
)
util
rand
.
Seed
(
1
)
generator
:=
&
testGenerator
{
Token
:
"ABC"
}
...
...
pkg/util/rand/rand.go
View file @
fdb5cefa
...
...
@@ -26,8 +26,8 @@ import (
var
letters
=
[]
rune
(
"abcdefghijklmnopqrstuvwxyz0123456789"
)
var
numLetters
=
len
(
letters
)
var
rng
=
struct
{
sync
.
Mutex
rand
*
rand
.
Rand
lock
sync
.
Mutex
}{
rand
:
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UTC
()
.
UnixNano
())),
}
...
...
@@ -39,10 +39,18 @@ func String(n int) string {
panic
(
"out-of-bounds value"
)
}
b
:=
make
([]
rune
,
n
)
rng
.
lock
.
Lock
()
defer
rng
.
lock
.
Unlock
()
rng
.
Lock
()
defer
rng
.
Unlock
()
for
i
:=
range
b
{
b
[
i
]
=
letters
[
rng
.
rand
.
Intn
(
numLetters
)]
}
return
string
(
b
)
}
// Seed seeds the rng with the provided seed.
func
Seed
(
seed
int64
)
{
rng
.
Lock
()
defer
rng
.
Unlock
()
rng
.
rand
=
rand
.
New
(
rand
.
NewSource
(
seed
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment