@@ -5,10 +5,12 @@ import (
5
5
"crypto/tls"
6
6
"io"
7
7
"log"
8
+ "math/rand"
8
9
"net/http"
9
10
"os"
10
11
"path/filepath"
11
12
"testing"
13
+ "time"
12
14
13
15
"github.com/docker/docker/pkg/fileutils"
14
16
sqlite "github.com/gwenn/gosqlite"
@@ -193,7 +195,7 @@ func TestDiff(t *testing.T) {
193
195
})
194
196
195
197
// Copy the database file to a temp location so we can make some changes
196
- newFile := filepath .Join (t .TempDir (), "diff-" + common . RandomString (8 )+ ".sqlite" )
198
+ newFile := filepath .Join (t .TempDir (), "diff-" + randomString (8 )+ ".sqlite" )
197
199
_ , err = fileutils .CopyFile (dbFile , newFile )
198
200
if err != nil {
199
201
t .Error (err )
@@ -270,7 +272,7 @@ func TestDiff(t *testing.T) {
270
272
assert .Len (t , diffs .Diff , 1 )
271
273
assert .Equal (t , "foo" , diffs .Diff [0 ].ObjectName )
272
274
assert .Equal (t , "table" , diffs .Diff [0 ].ObjectType )
273
- assert .Equal (t , common . DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
275
+ assert .Equal (t , DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
274
276
assert .Equal (t , "CREATE TABLE foo (first integer);" , diffs .Diff [0 ].Schema .Sql )
275
277
assert .Equal (t , "" , diffs .Diff [0 ].Schema .Before )
276
278
assert .Equal (t , "CREATE TABLE foo (first integer)" , diffs .Diff [0 ].Schema .After )
@@ -288,7 +290,7 @@ func TestDiff(t *testing.T) {
288
290
assert .Len (t , diffs .Diff , 1 )
289
291
assert .Equal (t , "foo" , diffs .Diff [0 ].ObjectName )
290
292
assert .Equal (t , "table" , diffs .Diff [0 ].ObjectType )
291
- assert .Equal (t , common . DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
293
+ assert .Equal (t , DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
292
294
assert .Equal (t , "CREATE TABLE foo (first integer);" , diffs .Diff [0 ].Schema .Sql )
293
295
assert .Equal (t , "" , diffs .Diff [0 ].Schema .Before )
294
296
assert .Equal (t , "CREATE TABLE foo (first integer)" , diffs .Diff [0 ].Schema .After )
@@ -306,7 +308,7 @@ func TestDiff(t *testing.T) {
306
308
assert .Len (t , diffs .Diff , 1 )
307
309
assert .Equal (t , "foo" , diffs .Diff [0 ].ObjectName )
308
310
assert .Equal (t , "table" , diffs .Diff [0 ].ObjectType )
309
- assert .Equal (t , common . DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
311
+ assert .Equal (t , DiffType ("add" ), diffs .Diff [0 ].Schema .ActionType )
310
312
assert .Equal (t , "" , diffs .Diff [0 ].Schema .Sql )
311
313
assert .Equal (t , "" , diffs .Diff [0 ].Schema .Before )
312
314
assert .Equal (t , "CREATE TABLE foo (first integer)" , diffs .Diff [0 ].Schema .After )
@@ -572,7 +574,7 @@ func TestUploadLive(t *testing.T) {
572
574
t .Error (err )
573
575
return
574
576
}
575
- dbB := filepath .Join (t .TempDir (), "diff-" + common . RandomString (8 )+ ".sqlite" )
577
+ dbB := filepath .Join (t .TempDir (), "diff-" + randomString (8 )+ ".sqlite" )
576
578
err = os .WriteFile (dbB , data , 0750 )
577
579
if err != nil {
578
580
t .Error (err )
@@ -617,6 +619,17 @@ func TestWebpage(t *testing.T) {
617
619
assert .Equal (t , "https://docker-dev.dbhub.io:9443/default/Assembly Election 2017.sqlite" , pageData .WebPage )
618
620
}
619
621
622
+ // randomString generates a random alphanumeric string of the desired length
623
+ func randomString (length int ) string {
624
+ rand .Seed (time .Now ().UnixNano ())
625
+ const alphaNum = "abcdefghijklmnopqrstuvwxyz0123456789"
626
+ randomString := make ([]byte , length )
627
+ for i := range randomString {
628
+ randomString [i ] = alphaNum [rand .Intn (len (alphaNum ))]
629
+ }
630
+ return string (randomString )
631
+ }
632
+
620
633
// serverConnection is a utility function that sets up the API connection object to the test server, ready for use
621
634
func serverConnection (apiKey string ) Connection {
622
635
// Create a new DBHub.io API object
0 commit comments