This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_test.go
88 lines (74 loc) · 1.82 KB
/
vm_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
package goitop
import (
"os"
"reflect"
"testing"
)
func TestClient_GetAllVM(t *testing.T) {
c := NewClient(os.Getenv("GOITOP_ADDR"), os.Getenv("GOITOP_USER"), os.Getenv("GOITOP_PASSWORD"))
vms, err := c.GetAllVM()
if err != nil {
t.Fatal(err)
}
if len(vms) == 0 {
t.Fatal("No VM returned")
}
}
func TestClient_VMCRUD(t *testing.T) {
c := NewClient(os.Getenv("GOITOP_ADDR"), os.Getenv("GOITOP_USER"), os.Getenv("GOITOP_PASSWORD"))
id, err := c.CreateVM("goitop", "9", "5", "1318", "5", "yes", "1", "")
if err != nil {
t.Fatal(err)
}
defer func() {
err = c.DeleteVM(id)
if err != nil {
t.Fatalf("Failed to delete VM with id %s", id)
}
}()
if id == "" {
t.Fatalf("Empty VM id returned after creation")
}
gotVM, err := c.GetVM(id)
if err != nil {
t.Fatal(err)
}
wantVM := VM{
Name: "goitop",
OrgID: "9",
EnvID: "5",
ClusterID: "1318",
ExploitationServiceID: "5",
ID: id,
Backup: "yes",
BackupID: "1",
Description: "goitop_test",
}
eq := reflect.DeepEqual(gotVM, wantVM)
if !eq {
t.Fatalf("VM created and VM read are not equals: got %v want %v", gotVM, wantVM)
}
err = c.UpdateVM(id, "goitop", "9", "4", "1318", "1", "no", "0", "")
if err != nil {
t.Fatal(err)
}
gotVM, err = c.GetVM(id)
if err != nil {
t.Fatal(err)
}
wantVM = VM{
Name: "goitop",
OrgID: "9",
EnvID: "4",
ClusterID: "1318",
ExploitationServiceID: "1",
ID: id,
Backup: "no",
BackupID: "0",
Description: "goitop_test",
}
eq = reflect.DeepEqual(gotVM, wantVM)
if !eq {
t.Fatalf("VM created and VM read are not equals: got %v want %v", gotVM, wantVM)
}
}