-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgetAvailableNodes.go
113 lines (95 loc) · 2.37 KB
/
getAvailableNodes.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
package main
import (
"fmt"
"testing"
"time"
"github.com/platinasystems/pcc-blackbox/models"
log "github.com/platinasystems/go-common/logs"
pcc "github.com/platinasystems/pcc-blackbox/lib"
"github.com/platinasystems/test"
)
func getNodes(t *testing.T) {
t.Run("getAvailableNodes", getAvailableNodes)
t.Run("TestNodeGroups", testNodeGroups)
}
func getAvailableNodes(t *testing.T) {
test.SkipIfDryRun(t)
res := models.InitTestResult(runID)
defer res.CheckTestAndSave(t, time.Now())
assert := test.Assert{t}
if nodes, err := Pcc.GetNodes(); err == nil {
for i := 0; i < len(*nodes); i++ {
node := (*nodes)[i]
id := node.Id
Nodes[id] = &node
NodebyHostIP[node.Host] = id
Env.setNodeId(node.Host, id)
}
} else {
msg := fmt.Sprintf("Error getting nodes: %v", err)
res.SetTestFailure(msg)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
}
func testNodeGroups(t *testing.T) {
test.SkipIfDryRun(t)
res := models.InitTestResult(runID)
defer res.CheckTestAndSave(t, time.Now())
assert := test.Assert{t}
var req pcc.NodeGroupRequest
req.Name = "my-test-group"
req.Description = "just a silly test"
err := Pcc.AddNodeGroup(&req)
if err != nil {
msg := fmt.Sprintf("Error getting nodes: %v", err)
res.SetTestFailure(msg)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
id := req.Id
group, err := Pcc.GetNodeGroupId(id)
if err != nil {
msg := fmt.Sprintf("Error GetNodeGroupId: %v", err)
res.SetTestFailure(msg)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
newDescription := "change it"
group.Description = newDescription
err = Pcc.UpdateNodeGroup(&group)
if err != nil {
msg := fmt.Sprintf("Error UpdateNodeGroupId: %v", err)
res.SetTestFailure(msg)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
groups, err := Pcc.GetNodeGroups()
if err != nil {
msg := fmt.Sprintf("Error UpdateNodeGroupId: %v", err)
res.SetTestFailure(msg)
log.AuctaLogger.Errorf("Error GetNodeGroups: %v", err)
assert.FailNow()
}
found := false
for _, g := range groups {
if g.ID == id {
if g.Description == newDescription {
found = true
break
}
}
}
if !found {
msg := "Error finding updated group"
res.SetTestFailure(msg)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
err = Pcc.DeleteNodeGroup(group.ID)
if err != nil {
msg := fmt.Sprintf("Error DeleteNodeGroup: %v", err)
log.AuctaLogger.Error(msg)
assert.FailNow()
}
}