-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipv4address_test.go
128 lines (122 loc) · 3.45 KB
/
ipv4address_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//go:build all || unittests
// +build all unittests
package infoblox
import (
"os"
"testing"
)
var (
ipv4AddressConfig = Config{
Host: os.Getenv("INFOBLOX_HOST"),
Port: os.Getenv("INFOBLOX_PORT"),
Username: os.Getenv("INFOBLOX_USERNAME"),
Password: os.Getenv("INFOBLOX_PASSWORD"),
Version: os.Getenv("INFOBLOX_VERSION"),
DisableTLSVerification: true,
}
ipv4AddressClient = New(ipv4AddressConfig)
ipv4AddressSequentialQuery = AddressQuery{
CIDR: "172.16.106.0/24",
Count: 20,
}
ipv4AddressSequentialQuery2 = AddressQuery{
CIDR: "172.19.10.0/24",
Count: 20,
}
ipv4AddressVerifyQuery = AddressQuery{
CIDR: "172.19.10.0/24",
StartAddress: "172.19.10.10",
EndAddress: "172.19.10.20",
}
ipv4AddressTestRange = Range{
CIDR: "172.19.10.0/24",
NetworkView: "default",
StartAddress: "172.19.10.10",
EndAddress: "172.19.10.20",
Comment: "Test Block",
DisableDHCP: newBool(true),
ExtensibleAttributes: newExtensibleAttribute(ExtensibleAttribute{
"Owner": ExtensibleAttributeValue{
Value: "testUser",
},
}),
}
ipv4AddressTestNetwork = Network{
CIDR: "172.19.10.0/24",
NetworkView: "default",
Comment: "testing",
ExtensibleAttributes: newExtensibleAttribute(ExtensibleAttribute{
"Owner": ExtensibleAttributeValue{
Value: "testUser",
},
"Gateway": ExtensibleAttributeValue{
Value: "172.19.10.1",
},
}),
}
ipv4AddressHostRecord = HostRecord{
Hostname: "test-api-12.auslab.cisco.com",
NetworkView: "default",
EnableDNS: newBool(true),
IPv4Addrs: []IPv4Addr{
{
//IPAddress: "func:nextavailableip:172.19.10.0/24",
IPAddress: "172.19.10.12",
},
},
ExtensibleAttributes: newExtensibleAttribute(ExtensibleAttribute{
"Owner": ExtensibleAttributeValue{
Value: "testUser",
},
}),
}
)
func TestGetSequentialAddressRange(t *testing.T) {
addresses, err := ipv4AddressClient.GetSequentialAddressRange(ipv4AddressSequentialQuery)
if err != nil {
t.Errorf("Error retrieving host record: %s", err)
}
prettyPrint(addresses)
}
func TestGetUsedAddressesWithinRange(t *testing.T) {
err := ipv4AddressClient.CreateNetwork(&ipv4AddressTestNetwork)
if err != nil {
t.Errorf("Error creating network: %s", err)
}
err = ipv4AddressClient.CreateRange(&ipv4AddressTestRange)
if err != nil {
t.Errorf("Error creating range: %s", err)
}
err = ipv4AddressClient.CreateHostRecord(&ipv4AddressHostRecord)
if err != nil {
t.Errorf("Error creating host record: %s", err)
}
addresses, err := ipv4AddressClient.GetSequentialAddressRange(ipv4AddressSequentialQuery2)
if err != nil {
t.Errorf("Error retrieving host record: %s", err)
}
prettyPrint(addresses)
addresses, err = ipv4AddressClient.GetUsedAddressesWithinRange(ipv4AddressVerifyQuery)
if err != nil {
t.Errorf("Error retrieving host record: %s", err)
}
prettyPrint(addresses)
err = ipv4AddressClient.DeleteHostRecord(ipv4AddressHostRecord.Ref)
if err != nil {
t.Errorf("Error deleting host record: %s", err)
}
err = ipv4AddressClient.DeleteRange(ipv4AddressTestRange.Ref)
if err != nil {
t.Errorf("Error deleting range: %s", err)
}
err = ipv4AddressClient.DeleteNetwork(ipv4AddressTestNetwork.Ref)
if err != nil {
t.Errorf("Error deleting network: %s", err)
}
}
func TestLogoutIPv4Address(t *testing.T) {
err := ipv4AddressClient.Logout()
if err != nil {
t.Errorf("Error logging out: %s", err)
}
}