-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupport_test.go
More file actions
60 lines (49 loc) · 1.42 KB
/
support_test.go
File metadata and controls
60 lines (49 loc) · 1.42 KB
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"database/sql"
"fmt"
"strconv"
"github.com/lib/pq"
)
func setupTestSuite() {
db.Unscoped().Delete(Entity{})
}
func createEntities(n int) {
i := 0
for i < n {
x := strconv.Itoa(i)
db.Create(&Entity{Name: "Test" + x, Credentials: Map{"access_key_id": "test-id", "secret_access_key": "test-key", "region": "eu-west-1"}})
i++
}
}
func createVcloudEntities(n int) {
i := 0
for i < n {
x := strconv.Itoa(i)
db.Create(&Entity{Name: "TestVcloud" + x, Type: "vcloud", Credentials: Map{"vcloud_url": "http://vcloud.com", "external_network": "ext-100", "username": "test", "password": "test"}})
i++
}
}
func createAWSEntities(n int) {
i := 0
for i < n {
x := strconv.Itoa(i)
db.Create(&Entity{Name: "TestAWS" + x, Type: "aws", Credentials: Map{"access_key_id": "test-id", "secret_access_key": "test-key", "region": "eu-west-1"}})
i++
}
}
func createTestDB(name string) error {
db, derr := sql.Open("postgres", "user=postgres sslmode=disable")
if derr != nil {
return derr
}
_, derr = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", pq.QuoteIdentifier(name)))
if derr != nil {
return derr
}
_, derr = db.Exec(fmt.Sprintf("CREATE DATABASE %s", pq.QuoteIdentifier(name)))
return derr
}