Browse code

Fixes #11721 removed GenerateRandomString

Signed-off-by: Peter Esbensen <pkesbensen@gmail.com>

gofmt

Signed-off-by: Peter Esbensen <pkesbensen@gmail.com>

Peter Esbensen authored on 2015/04/01 23:21:07
Showing 4 changed files
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"github.com/docker/docker/pkg/ioutils"
14
-	"github.com/docker/docker/pkg/stringutils"
14
+	"github.com/docker/docker/pkg/stringid"
15 15
 )
16 16
 
17 17
 // Installer is a standard interface for objects which can "install" themselves
... ...
@@ -78,7 +78,7 @@ func (eng *Engine) RegisterCatchall(catchall Handler) {
78 78
 func New() *Engine {
79 79
 	eng := &Engine{
80 80
 		handlers: make(map[string]Handler),
81
-		id:       stringutils.GenerateRandomString(),
81
+		id:       stringid.GenerateRandomID(),
82 82
 		Stdout:   os.Stdout,
83 83
 		Stderr:   os.Stderr,
84 84
 		Stdin:    os.Stdin,
... ...
@@ -1,23 +1,10 @@
1 1
 package stringutils
2 2
 
3 3
 import (
4
-	"crypto/rand"
5
-	"encoding/hex"
6
-	"io"
7 4
 	mathrand "math/rand"
8 5
 	"time"
9 6
 )
10 7
 
11
-// Generate 32 chars random string
12
-func GenerateRandomString() string {
13
-	id := make([]byte, 32)
14
-
15
-	if _, err := io.ReadFull(rand.Reader, id); err != nil {
16
-		panic(err) // This shouldn't happen
17
-	}
18
-	return hex.EncodeToString(id)
19
-}
20
-
21 8
 // Generate alpha only random stirng with length n
22 9
 func GenerateRandomAlphaOnlyString(n int) string {
23 10
 	// make a really long string
... ...
@@ -2,34 +2,12 @@ package stringutils
2 2
 
3 3
 import "testing"
4 4
 
5
-func TestRandomString(t *testing.T) {
6
-	str := GenerateRandomString()
7
-	if len(str) != 64 {
8
-		t.Fatalf("Id returned is incorrect: %s", str)
9
-	}
10
-}
11
-
12
-func TestRandomStringUniqueness(t *testing.T) {
13
-	repeats := 25
14
-	set := make(map[string]struct{}, repeats)
15
-	for i := 0; i < repeats; i = i + 1 {
16
-		str := GenerateRandomString()
17
-		if len(str) != 64 {
18
-			t.Fatalf("Id returned is incorrect: %s", str)
19
-		}
20
-		if _, ok := set[str]; ok {
21
-			t.Fatalf("Random number is repeated")
22
-		}
23
-		set[str] = struct{}{}
24
-	}
25
-}
26
-
27 5
 func testLengthHelper(generator func(int) string, t *testing.T) {
28 6
 	expectedLength := 20
29 7
 	s := generator(expectedLength)
30 8
 	if len(s) != expectedLength {
31 9
 		t.Fatalf("Length of %s was %d but expected length %d", s, len(s), expectedLength)
32
-	}	
10
+	}
33 11
 }
34 12
 
35 13
 func testUniquenessHelper(generator func(int) string, t *testing.T) {
... ...
@@ -65,7 +43,7 @@ func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) {
65 65
 }
66 66
 
67 67
 func TestGenerateRandomAsciiStringLength(t *testing.T) {
68
-	testLengthHelper(GenerateRandomAsciiString, t) 
68
+	testLengthHelper(GenerateRandomAsciiString, t)
69 69
 }
70 70
 
71 71
 func TestGenerateRandomAsciiStringUniqueness(t *testing.T) {
... ...
@@ -24,7 +24,7 @@ import (
24 24
 	"github.com/docker/docker/pkg/fileutils"
25 25
 	"github.com/docker/docker/pkg/ioutils"
26 26
 	"github.com/docker/docker/pkg/jsonmessage"
27
-	"github.com/docker/docker/pkg/stringutils"
27
+	"github.com/docker/docker/pkg/stringid"
28 28
 )
29 29
 
30 30
 type KeyValuePair struct {
... ...
@@ -313,7 +313,7 @@ var globalTestID string
313 313
 // new directory.
314 314
 func TestDirectory(templateDir string) (dir string, err error) {
315 315
 	if globalTestID == "" {
316
-		globalTestID = stringutils.GenerateRandomString()[:4]
316
+		globalTestID = stringid.GenerateRandomID()[:4]
317 317
 	}
318 318
 	prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, GetCallerName(2))
319 319
 	if prefix == "" {