From 72e1dd5a52908405544df4f0b3bc596749435f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 18 Nov 2019 09:28:51 +0100 Subject: [PATCH] (#25) Use Google's UUID for generating compose's identifier --- compose_test.go | 7 ++++--- go.mod | 1 + go.sum | 2 ++ utility.go | 19 ------------------- utility_test.go | 15 --------------- 5 files changed, 7 insertions(+), 37 deletions(-) delete mode 100644 utility.go delete mode 100644 utility_test.go diff --git a/compose_test.go b/compose_test.go index 7542dc6477a..e8816ae950f 100644 --- a/compose_test.go +++ b/compose_test.go @@ -5,13 +5,14 @@ import ( "strings" "testing" + "github.com/google/uuid" "github.com/stretchr/testify/assert" ) func TestLocalDockerCompose(t *testing.T) { path := "./testresources/docker-compose.yml" - identifier := strings.ToLower(RandomString(6)) + identifier := strings.ToLower(uuid.New().String()) compose := NewLocalDockerCompose([]string{path}, identifier) @@ -36,7 +37,7 @@ func TestLocalDockerCompose(t *testing.T) { func TestLocalDockerComposeWithEnvironment(t *testing.T) { path := "./testresources/docker-compose.yml" - identifier := strings.ToLower(RandomString(6)) + identifier := strings.ToLower(uuid.New().String()) compose := NewLocalDockerCompose([]string{path}, identifier) destroyFn := func() { @@ -66,7 +67,7 @@ func TestLocalDockerComposeWithMultipleComposeFiles(t *testing.T) { "testresources/docker-compose-override.yml", } - identifier := strings.ToLower(RandomString(6)) + identifier := strings.ToLower(uuid.New().String()) compose := NewLocalDockerCompose(composeFiles, identifier) destroyFn := func() { diff --git a/go.mod b/go.mod index 2df0725f40a..4a92a3b47af 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/go-redis/redis v6.15.5+incompatible github.com/go-sql-driver/mysql v1.4.1 github.com/gogo/protobuf v1.2.0 // indirect + github.com/google/uuid v1.1.1 github.com/gorilla/context v1.1.1 // indirect github.com/gorilla/mux v1.6.2 // indirect github.com/kr/pretty v0.1.0 // indirect diff --git a/go.sum b/go.sum index 811d78c24a7..c10dbd60b36 100644 --- a/go.sum +++ b/go.sum @@ -31,6 +31,8 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= diff --git a/utility.go b/utility.go deleted file mode 100644 index 28a530967cf..00000000000 --- a/utility.go +++ /dev/null @@ -1,19 +0,0 @@ -package testcontainers - -import ( - "math/rand" - "time" -) - -var alfabet = []rune("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") - -// RandomString returns a random string -func RandomString(length int) string { - rand.Seed(time.Now().UnixNano()) - - b := make([]rune, length) - for i := range b { - b[i] = alfabet[rand.Intn(len(alfabet))] - } - return string(b) -} diff --git a/utility_test.go b/utility_test.go deleted file mode 100644 index 7cb53a514c8..00000000000 --- a/utility_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package testcontainers - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRandomStringHonorsLength(t *testing.T) { - r := RandomString(10) - assert.Equal(t, 10, len(r)) - - r = RandomString(0) - assert.Equal(t, 0, len(r)) -}