forked from LunaNode/lobster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.go
55 lines (46 loc) · 1.34 KB
/
testing.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
package lobster
import "github.com/gorilla/mux"
import "github.com/LunaNode/lobster/utils"
const TEST_BANDWIDTH = 1000
var testTables []string = []string{"users", "region_bandwidth", "vms", "plans", "charges", "sessions", "form_tokens", "antiflood"}
func TestReset() {
cfg = &Config{
Default: ConfigDefault{
Debug: true,
},
Billing: ConfigBilling{
BandwidthOverageFee: 0.003,
},
Database: ConfigDatabase{
Host: "localhost",
Username: "lobstertest",
Password: "",
Name: "lobstertest",
},
Novnc: ConfigNovnc{
Listen: "127.0.0.1:6080",
Url: "TOKEN",
},
}
db = MakeDatabase()
// clear all tables
for _, table := range testTables {
db.Exec("DELETE FROM " + table)
}
}
func TestSetup() {
router = mux.NewRouter()
db = MakeDatabase()
}
// Creates user and returns user id.
func TestUser() int {
result := db.Exec("INSERT INTO users (username, password, credit) VALUES (?, '', 1000000)", utils.Uid(8))
return result.LastInsertId()
}
func TestVm(userId int) int {
result := db.Exec("INSERT INTO plans (name, price, ram, cpu, storage, bandwidth) VALUES ('', 6000, 512, 1, 15, ?)", TEST_BANDWIDTH)
planId := result.LastInsertId()
result = db.Exec("INSERT INTO vms (user_id, region, plan_id, name, status) VALUES (?, 'test', ?, '', 'active')", userId, planId)
vmId := result.LastInsertId()
return vmId
}