-
Notifications
You must be signed in to change notification settings - Fork 1
/
objects_test.go
114 lines (88 loc) · 2.53 KB
/
objects_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
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
114
package goidoit
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetObject(t *testing.T) {
server := idoitAPIStub()
api, err := NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
res, err := api.GetObject("test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObject([]int{1, 2})
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObject(1)
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObject(struct{ Foo string }{"bar"})
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestGetObjectByType(t *testing.T) {
server := idoitAPIStub()
api, err := NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
res, err := api.GetObjectByType("VirtualMachines", "test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObjectByType("VirtualMachines", 1)
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObjectByType("VirtualMachines", []int{1, 2})
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObjectByType("VirtualMachines", struct{ Foo string }{"bar"})
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestGetObjectsByType(t *testing.T) {
server := idoitAPIStub()
api, err := NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
res, err := api.GetObjectsByType("C__CATG_TEST")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObjectsByType("VirtualMachines")
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestGetObjTypeCat(t *testing.T) {
server := idoitAPIStub()
api, err := NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
res, err := api.GetObjTypeCat("test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.GetObjTypeCat(1)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestAlterObj(t *testing.T) {
server := idoitAPIStub()
api, err := NewLogin(server.URL, "apikey", "username", "password")
assert.Nil(t, err)
res, err := api.CreateObj("test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.UpdateObj("test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.DeleteObj("test")
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.DeleteObj(1)
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.Quickpurge(1)
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.Quickpurge([]int{1, 2})
assert.Nil(t, err)
assert.NotNil(t, res)
res, err = api.Quickpurge("test")
assert.Equal(t, fmt.Errorf("Input type is not int or []int"), err)
assert.Equal(t, GenericResponse{}, res)
}