-
Notifications
You must be signed in to change notification settings - Fork 11
/
dbhub_test.go
643 lines (562 loc) · 19.4 KB
/
dbhub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
package dbhub
import (
"bytes"
"crypto/tls"
"io"
"log"
"math/rand"
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/docker/docker/pkg/fileutils"
sqlite "github.com/gwenn/gosqlite"
"github.com/sqlitebrowser/dbhub.io/common"
"github.com/stretchr/testify/assert"
)
// For now, the tests require the DBHub.io dev docker container be running on its standard
// ports (that means the API server is listening on https://localhost:9444)
func TestMain(m *testing.M) {
log.Println("Seeding the database...")
// Disable https cert validation for our tests
insecureTLS := tls.Config{InsecureSkipVerify: true}
insecureTransport := http.Transport{TLSClientConfig: &insecureTLS}
client := http.Client{Transport: &insecureTransport}
// Seed the database
resp, err := client.Get("https://localhost:9443/x/test/seed")
if err != nil {
log.Fatal(err)
}
if resp.StatusCode != 200 {
log.Fatalf("Database seed request returned http code '%d'. Aborting tests.", resp.StatusCode)
}
log.Println("Database seeding completed ok.")
// Run the tests
log.Println("Running the tests...")
m.Run()
}
// TestBranches verifies retrieving the branch and default branch information using the API
func TestBranches(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve branch details for the database
branches, defaultBranch, err := conn.Branches("default", "Assembly Election 2017 with view.sqlite")
if err != nil {
t.Error(err)
return
}
// Verify the returned branch information matches what we're expecting
assert.Len(t, branches, 1)
assert.Contains(t, branches, "main")
assert.Equal(t, "main", defaultBranch)
}
// TestColumns verifies retrieving the list of column names for a database using the API
func TestColumns(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the column info for a table or view in the remote database
table := "Candidate_Names"
columns, err := conn.Columns("default", "Assembly Election 2017 with view.sqlite", Identifier{Branch: "main"}, table)
if err != nil {
log.Fatal(err)
}
// Verify the returned column information matches what we're expecting
assert.Len(t, columns, 2)
assert.Contains(t, columns[0].Name, "Firstname")
assert.Equal(t, "Surname", columns[1].Name)
}
// TestCommits verifies retrieving commit information for standard databases using the API
func TestCommits(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the commit info for a remote database
commits, err := conn.Commits("default", "Assembly Election 2017 with view.sqlite")
if err != nil {
log.Fatal(err)
}
// Verify the returned commit information matches what we're expecting
assert.Len(t, commits, 1)
// Abort early if the returned length of commits isn't what we're expecting
if len(commits) != 1 {
return
}
// Retrieve the the first commit id
var ids []string
for id := range commits {
ids = append(ids, id)
}
firstID := ids[0]
// Verify the commit information is what we're expecting
assert.Equal(t, "default@docker-dev.dbhub.io", commits[firstID].AuthorEmail)
assert.Equal(t, "Default system user", commits[firstID].AuthorName)
assert.Equal(t, "Initial commit", commits[firstID].Message)
assert.Equal(t, "Assembly Election 2017 with view.sqlite", commits[firstID].Tree.Entries[0].Name)
assert.Equal(t, int64(73728), commits[firstID].Tree.Entries[0].Size)
assert.Equal(t, "9cb18719bddb949043abc1ba089dd7c4845ab024ddbe4ad19e9334da4e5b8cdc", commits[firstID].Tree.Entries[0].Sha256)
assert.Equal(t, "9348ddfd44da5a127c59141981954746a860ec8e03e0412cf3af7134af0f97e2", commits[firstID].Tree.Entries[0].LicenceSHA)
}
// TestDatabases verifies retrieving the list of standard databases using the API
func TestDatabases(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the list of databases for the user
databases, err := conn.Databases()
if err != nil {
t.Errorf("Connecting to the API server failed: %v", err)
return
}
// If no databases were found, the test failed
if len(databases) == 0 {
t.Error("No databases found")
return
}
// Verify the expected database names were returned, and only them
assert.Contains(t, databases, "Assembly Election 2017 with view.sqlite")
assert.Contains(t, databases, "Assembly Election 2017.sqlite")
assert.Len(t, databases, 2)
return
}
// TestDatabases verifies retrieving the list of live databases using the API
func TestDatabasesLive(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the list of live databases for the user
databases, err := conn.DatabasesLive()
if err != nil {
t.Error(err)
return
}
// If no databases were found, the test failed
if len(databases) == 0 {
t.Error("No databases found")
return
}
// Verify the expected database name was returned
assert.Contains(t, databases, "Join Testing with index.sqlite")
assert.Len(t, databases, 1)
return
}
// TestDiff verifies the Diff API call
func TestDiff(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Read the example database file into memory
dbFile := filepath.Join("examples", "upload", "example.db")
z, err := os.ReadFile(dbFile)
if err != nil {
t.Error(err)
return
}
// Upload the example database
dbName := "uploadtest1.sqlite"
err = conn.Upload(dbName, UploadInformation{}, &z)
if err != nil {
t.Error(err)
return
}
t.Cleanup(func() {
// Delete the uploaded database when the test exits
err = conn.Delete(dbName)
if err != nil {
t.Error(err)
return
}
})
// Copy the database file to a temp location so we can make some changes
newFile := filepath.Join(t.TempDir(), "diff-"+randomString(8)+".sqlite")
_, err = fileutils.CopyFile(dbFile, newFile)
if err != nil {
t.Error(err)
return
}
// Make some changes to the copied database file
sdb, err := sqlite.Open(newFile, sqlite.OpenReadWrite|sqlite.OpenFullMutex)
if err != nil {
t.Error()
return
}
dbQuery := `
CREATE TABLE foo (first integer);
INSERT INTO foo (first) values (10);
INSERT INTO foo (first) values (20);`
err = sdb.Exec(dbQuery)
if err != nil {
t.Error()
sdb.Close()
return
}
sdb.Close()
// Retrieve the initial commit id for the database
dbOwner := "default"
commitMap, err := conn.Commits(dbOwner, dbName)
if err != nil {
t.Error(err)
return
}
var commits []string
for idx := range commitMap {
commits = append(commits, idx)
}
firstCommit := commits[0]
// Upload the copied file as a new commit
z, err = os.ReadFile(newFile)
if err != nil {
t.Error(err)
return
}
uploadCommit := Identifier{CommitID: firstCommit}
err = conn.Upload(dbName, UploadInformation{Ident: uploadCommit}, &z)
if err != nil {
t.Error(err)
return
}
// Retrieve the new commit id for the database
commitMap, err = conn.Commits(dbOwner, dbName)
if err != nil {
t.Error(err)
return
}
var secondCommit string
for idx := range commitMap {
if idx != firstCommit {
secondCommit = idx
}
}
// Do the diff using NewPkMerge
commit1 := Identifier{CommitID: firstCommit}
commit2 := Identifier{CommitID: secondCommit}
diffs, err := conn.Diff(dbOwner, dbName, commit1, "", "", commit2, NewPkMerge)
if err != nil {
t.Error(err)
return
}
// Verify the changes
assert.Len(t, diffs.Diff, 1)
assert.Equal(t, "foo", diffs.Diff[0].ObjectName)
assert.Equal(t, "table", diffs.Diff[0].ObjectType)
assert.Equal(t, DiffType("add"), diffs.Diff[0].Schema.ActionType)
assert.Equal(t, "CREATE TABLE foo (first integer);", diffs.Diff[0].Schema.Sql)
assert.Equal(t, "", diffs.Diff[0].Schema.Before)
assert.Equal(t, "CREATE TABLE foo (first integer)", diffs.Diff[0].Schema.After)
assert.Equal(t, `INSERT INTO "foo"("first") VALUES(10);`, diffs.Diff[0].Data[0].Sql)
assert.Equal(t, `INSERT INTO "foo"("first") VALUES(20);`, diffs.Diff[0].Data[1].Sql)
// Diff with PreservePkMerge
diffs, err = conn.Diff(dbOwner, dbName, commit1, "", "", commit2, PreservePkMerge)
if err != nil {
t.Error(err)
return
}
// Verify the changes
assert.Len(t, diffs.Diff, 1)
assert.Equal(t, "foo", diffs.Diff[0].ObjectName)
assert.Equal(t, "table", diffs.Diff[0].ObjectType)
assert.Equal(t, DiffType("add"), diffs.Diff[0].Schema.ActionType)
assert.Equal(t, "CREATE TABLE foo (first integer);", diffs.Diff[0].Schema.Sql)
assert.Equal(t, "", diffs.Diff[0].Schema.Before)
assert.Equal(t, "CREATE TABLE foo (first integer)", diffs.Diff[0].Schema.After)
assert.Equal(t, `INSERT INTO "foo"("first") VALUES(10);`, diffs.Diff[0].Data[0].Sql)
assert.Equal(t, `INSERT INTO "foo"("first") VALUES(20);`, diffs.Diff[0].Data[1].Sql)
// Diff with NoMerge
diffs, err = conn.Diff(dbOwner, dbName, commit1, "", "", commit2, NoMerge)
if err != nil {
t.Error(err)
return
}
// Verify the changes
assert.Len(t, diffs.Diff, 1)
assert.Equal(t, "foo", diffs.Diff[0].ObjectName)
assert.Equal(t, "table", diffs.Diff[0].ObjectType)
assert.Equal(t, DiffType("add"), diffs.Diff[0].Schema.ActionType)
assert.Equal(t, "", diffs.Diff[0].Schema.Sql)
assert.Equal(t, "", diffs.Diff[0].Schema.Before)
assert.Equal(t, "CREATE TABLE foo (first integer)", diffs.Diff[0].Schema.After)
assert.Equal(t, "", diffs.Diff[0].Data[0].Sql)
assert.Equal(t, "", diffs.Diff[0].Data[1].Sql)
}
// TestExecute verifies the Execute API call
func TestExecute(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Execute a SQL statement
dbQuery := `INSERT INTO table1 (id, Name) VALUES (7, "Stuff")`
rowsChanged, err := conn.Execute("default", "Join Testing with index.sqlite", dbQuery)
if err != nil {
t.Error(err)
return
}
// Verify the result
assert.Equal(t, 1, rowsChanged)
// Execute another SQL statement
dbQuery = `UPDATE table1 SET Name = "New Stuff" WHERE id = 1 OR id = 7`
rowsChanged, err = conn.Execute("default", "Join Testing with index.sqlite", dbQuery)
if err != nil {
t.Error(err)
return
}
// Verify the result
assert.Equal(t, 2, rowsChanged)
}
// TestIndexes verifies the Indexes API call
func TestIndexes(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the index information for the database
indexes, err := conn.Indexes("default", "Join Testing with index.sqlite", Identifier{})
if err != nil {
t.Error(err)
return
}
// Verify the index information
assert.Len(t, indexes, 1)
assert.Equal(t, "table1", indexes[0].Table)
assert.Equal(t, "stuff", indexes[0].Name)
assert.Empty(t, indexes[0].Columns[0].CID)
assert.Equal(t, "id", indexes[0].Columns[0].Name)
}
// TestMetadata verifies the metadata API call
func TestMetadata(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the metadata information for the database
meta, err := conn.Metadata("default", "Assembly Election 2017 with view.sqlite")
if err != nil {
t.Error(err)
return
}
// Get the commit id of the first commit
var firstCommit string
for _, c := range meta.Commits {
firstCommit = c.ID
}
// Verify the metadata info
assert.Equal(t, "https://docker-dev.dbhub.io:9443/default/Assembly Election 2017 with view.sqlite", meta.WebPage)
assert.Equal(t, "main", meta.DefBranch)
assert.Equal(t, "", meta.Branches["main"].Description)
assert.Equal(t, 1, meta.Branches["main"].CommitCount)
assert.Empty(t, meta.Releases)
assert.Empty(t, meta.Tags)
assert.Equal(t, firstCommit, meta.Commits[firstCommit].ID)
assert.Equal(t, "Initial commit", meta.Commits[firstCommit].Message)
assert.Equal(t, "Default system user", meta.Commits[firstCommit].AuthorName)
assert.Equal(t, "default@docker-dev.dbhub.io", meta.Commits[firstCommit].AuthorEmail)
assert.Equal(t, int64(73728), meta.Commits[firstCommit].Tree.Entries[0].Size)
}
// TestQuery verifies the Query API call
func TestQuery(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Query the database
dbQuery := `
SELECT id, Name
FROM table1
ORDER BY Name DESC`
result, err := conn.Query("default", "Join Testing with index.sqlite", Identifier{}, false, dbQuery)
if err != nil {
t.Error(err)
return
}
// Verify the result
assert.Len(t, result.Rows, 7)
assert.Contains(t, result.Rows, ResultRow{Fields: []string{"2", "Bar"}})
assert.Contains(t, result.Rows, ResultRow{Fields: []string{"3", "Baz"}})
assert.Contains(t, result.Rows, ResultRow{Fields: []string{"4", "Blumph"}})
assert.Contains(t, result.Rows, ResultRow{Fields: []string{"5", "Blargo"}})
assert.Contains(t, result.Rows, ResultRow{Fields: []string{"6", "Batty"}})
}
// TestReleases verifies the Releases API call
func TestReleases(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the releases for a database
releases, err := conn.Releases("default", "Assembly Election 2017.sqlite")
if err != nil {
t.Error(err)
return
}
// Verify the retrieved information
assert.Len(t, releases, 2)
assert.Equal(t, "First release", releases["first"].Description)
assert.Equal(t, "Example Releaser", releases["first"].ReleaserName)
assert.Equal(t, "example@example.org", releases["first"].ReleaserEmail)
assert.Equal(t, "Second release", releases["second"].Description)
assert.Equal(t, "Example Releaser", releases["second"].ReleaserName)
assert.Equal(t, "example@example.org", releases["second"].ReleaserEmail)
}
// TestTables verifies the Tables API call
func TestTables(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve table information for a database
tbls, err := conn.Tables("default", "Assembly Election 2017.sqlite", Identifier{})
if err != nil {
t.Error(err)
return
}
// Verify the returned information
assert.Len(t, tbls, 3)
assert.Contains(t, tbls, "Candidate_Information")
assert.Contains(t, tbls, "Constituency_Turnout_Information")
assert.Contains(t, tbls, "Elected_Candidates")
}
// TestTags verifies the Tags API call
func TestTags(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Retrieve the tags for a database
tags, err := conn.Tags("default", "Assembly Election 2017.sqlite")
if err != nil {
t.Error(err)
return
}
// Verify the retrieved information
assert.Len(t, tags, 2)
assert.Equal(t, "First tag", tags["first"].Description)
assert.Equal(t, "Example Tagger", tags["first"].TaggerName)
assert.Equal(t, "example@example.org", tags["first"].TaggerEmail)
assert.Equal(t, "Second tag", tags["second"].Description)
assert.Equal(t, "Example Tagger", tags["second"].TaggerName)
assert.Equal(t, "example@example.org", tags["second"].TaggerEmail)
}
// TestUpload verifies uploading a standard database via the API
func TestUpload(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Read the example database file into memory
dbFile := filepath.Join("examples", "upload", "example.db")
z, err := os.ReadFile(dbFile)
if err != nil {
t.Error(err)
return
}
// Upload the example database
dbName := "testupload.sqlite"
err = conn.Upload(dbName, UploadInformation{}, &z)
if err != nil {
t.Error(err)
return
}
// Verify the file contents. This is done by downloading the database and doing a byte comparison to ensure its
// identical to the upload
downloaded, err := conn.Download("default", dbName, Identifier{})
if err != nil {
t.Error(err)
return
}
t.Cleanup(func() {
// Delete the uploaded file when the function exits
err = conn.Delete(dbName)
if err != nil {
t.Error(err)
return
}
})
data, err := io.ReadAll(downloaded)
if err != nil {
t.Error(err)
return
}
result := bytes.Compare(z, data)
if result != 0 {
t.Errorf("Standard database upload succeeded, but failed verification when downloading it and comparing to the original")
return
}
}
// TestUploadLive verifies uploading a live database via the API
func TestUploadLive(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Read the example database file into memory
dbA := filepath.Join("examples", "upload", "example.db")
z, err := os.ReadFile(dbA)
if err != nil {
t.Error(err)
return
}
// Upload the database
dbName := "testuploadlive.sqlite"
err = conn.UploadLive(dbName, &z)
if err != nil {
t.Error(err)
return
}
// *** Verify the database ***
// This is done by downloading and comparing (database diff) the database contents with the database file that was uploaded
downloaded, err := conn.Download("default", dbName, Identifier{})
if err != nil {
t.Error(err)
return
}
t.Cleanup(func() {
// Delete the uploaded database when the test exits
err = conn.Delete(dbName)
if err != nil {
t.Error(err)
return
}
})
data, err := io.ReadAll(downloaded)
if err != nil {
t.Error(err)
return
}
dbB := filepath.Join(t.TempDir(), "diff-"+randomString(8)+".sqlite")
err = os.WriteFile(dbB, data, 0750)
if err != nil {
t.Error(err)
return
}
// Do the comparison
diffs, err := common.DBDiff(dbA, dbB, common.NoMerge, false)
if err != nil {
t.Error(err)
return
}
assert.Empty(t, diffs.Diff)
}
// TestViews verifies the Views API call
func TestViews(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Get the list of views in the database
views, err := conn.Views("default", "Assembly Election 2017 with view.sqlite", Identifier{})
if err != nil {
t.Error(err)
return
}
assert.Len(t, views, 1)
assert.Equal(t, "Candidate_Names", views[0])
}
// TestWebpage verifies the Webpage API call
func TestWebpage(t *testing.T) {
// Create the local test server connection
conn := serverConnection("Rh3fPl6cl84XEw2FeWtj-FlUsn9OrxKz9oSJfe6kho7jT_1l5hizqw")
// Gather the data then test the result
pageData, err := conn.Webpage("default", "Assembly Election 2017.sqlite")
if err != nil {
t.Error(err)
return
}
assert.Equal(t, "https://docker-dev.dbhub.io:9443/default/Assembly Election 2017.sqlite", pageData.WebPage)
}
// randomString generates a random alphanumeric string of the desired length
func randomString(length int) string {
rand.Seed(time.Now().UnixNano())
const alphaNum = "abcdefghijklmnopqrstuvwxyz0123456789"
randomString := make([]byte, length)
for i := range randomString {
randomString[i] = alphaNum[rand.Intn(len(alphaNum))]
}
return string(randomString)
}
// serverConnection is a utility function that sets up the API connection object to the test server, ready for use
func serverConnection(apiKey string) Connection {
// Create a new DBHub.io API object
db, err := New(apiKey)
if err != nil {
log.Fatal(err)
}
db.ChangeServer("https://localhost:9444")
db.ChangeVerifyServerCert(false)
return db
}