Debian Codegraph @

sls/machine_group_test.go

raw symbols SCIP
1 package sls
2
3 import (
4 "fmt"
5 "testing"
6 )
7
8 func TestListMachineGroups(t *testing.T) {
9 p := DefaultProject(t)
10 groups, err := p.ListMachineGroup(0, 100)
11 if err != nil {
12 fmt.Printf("Error in list groups %s \n", err)
13 t.FailNow()
14 }
15
16 fmt.Println(groups)
17 }
18
19 func TestCreateMachineGroup(t *testing.T) {
20 p := DefaultProject(t)
21 groupName := "testGroup"
22 group := &MachineGroup{
23 Name: groupName,
24 MachineIdentifyType: "ip",
25 Attribute: &GroupAttribute{},
26 MachineList: []string{
27 "127.0.0.1",
28 "127.0.0.2",
29 },
30 }
31 err := p.CreateMachineGroup(group)
32 if err != nil {
33 if e, ok := err.(*Error); ok && e.Code != "GroupAlreadyExist" {
34 t.Fatalf("Create machine error: %v", err)
35 }
36 }
37
38 mg, err := p.MachineGroup(groupName)
39 if err != nil {
40 t.Fatalf("Find machine error: %v", err)
41 }
42
43 _, err = p.ListMachines("testGroup", 0, 100)
44 if err != nil {
45 t.Fatalf("List machine error: %v", err)
46 }
47
48 //Update MachineGroup
49 mg.MachineList = append(mg.MachineList, "127.0.0.3")
50 if err = p.UpdateMachineGroup(mg); err != nil {
51 t.Fatalf("Update machine error: %v", err)
52 }
53
54 if err = p.DeleteMachineGroup(groupName); err != nil {
55 t.Fatalf("Delete machine error: %v", err)
56 }
57 }
58
59 func TestClient_ListMachineGroups(t *testing.T) {
60 client := NewTestClientForDebug()
61 p, err := client.Project(TestProjectName)
62 if err != nil {
63 t.Fatalf("get project fail: %++v", err)
64 }
65
66 machines, err := p.ListMachines(TestMachineGroup, 0, 100)
67 if err != nil {
68 t.Fatalf("Error %++v", err)
69 } else {
70 for index, machine := range machines.Machines {
71 t.Logf("Machines[%d] = %++v", index, machine)
72 }
73
74 }
75 }