-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwnc_test.go
More file actions
136 lines (127 loc) · 3.99 KB
/
wnc_test.go
File metadata and controls
136 lines (127 loc) · 3.99 KB
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
129
130
131
132
133
134
135
136
package wnc
import (
"log/slog"
"testing"
"time"
)
// TestNewClient tests the creation of a new unified client.
func TestNewClient(t *testing.T) {
testCases := []struct {
name string
host string
token string
opts []Option
expectError bool
}{
{
name: "ValidClient",
host: "192.168.1.100",
token: "YWRtaW46cGFzc3dvcmQ=", // base64 encoded "admin:password"
opts: nil,
expectError: false,
},
{
name: "ValidClientWithOptions",
host: "wnc.example.internal",
token: "YWRtaW46cGFzc3dvcmQ=",
opts: []Option{WithTimeout(30 * time.Second), WithInsecureSkipVerify(true)},
expectError: false,
},
{
name: "ValidClientWithLoggerAndUserAgent",
host: "controller.example.internal",
token: "YWRtaW46cGFzc3dvcmQ=",
opts: []Option{WithLogger(slog.New(slog.DiscardHandler)), WithUserAgent("custom-agent/1.0")},
expectError: false,
},
{
name: "InvalidHost",
host: "",
token: "YWRtaW46cGFzc3dvcmQ=",
opts: nil,
expectError: true,
},
{
name: "InvalidToken",
host: "controller.example.com",
token: "",
opts: nil,
expectError: true,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
client, err := NewClient(tt.host, tt.token, tt.opts...)
if tt.expectError {
if err == nil {
t.Error("Expected error, but got none")
}
if client != nil {
t.Error("Expected nil client on error")
}
} else {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if client == nil {
t.Error("Expected client, but got nil")
}
}
})
}
}
// TestClientServiceAccessors tests that all service accessors return non-nil services.
func TestClientServiceAccessors(t *testing.T) {
client, err := NewClient("controller.example.com", "dGVzdDp0ZXN0")
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
// Test Core() method
coreClient := client.Core()
if coreClient == nil {
t.Error("Core() returned nil")
}
// Test all service accessors - verify they don't panic and return valid structs
defer func() {
if r := recover(); r != nil {
t.Errorf("Service accessor panicked: %v", r)
}
}()
// Test service accessors return valid services
_ = client.AFC() // Should not panic
_ = client.AP() // Should not panic
_ = client.APF() // Should not panic
_ = client.AWIPS() // Should not panic
_ = client.BLE() // Should not panic
_ = client.Client() // Should not panic
_ = client.Controller() // Should not panic
_ = client.CTS() // Should not panic
_ = client.Dot11() // Should not panic
_ = client.Dot15() // Should not panic
_ = client.Fabric() // Should not panic
_ = client.Flex() // Should not panic
_ = client.General() // Should not panic
_ = client.Geolocation() // Should not panic
_ = client.Hyperlocation() // Should not panic
_ = client.LISP() // Should not panic
_ = client.Location() // Should not panic
_ = client.Mcast() // Should not panic
_ = client.MDNS() // Should not panic
_ = client.Mesh() // Should not panic
_ = client.Mobility() // Should not panic
_ = client.NMSP() // Should not panic
_ = client.Radio() // Should not panic
_ = client.RF() // Should not panic
_ = client.RFID() // Should not panic
_ = client.Rogue() // Should not panic
_ = client.RRM() // Should not panic
_ = client.Site() // Should not panic
_ = client.Spaces() // Should not panic
_ = client.URWB() // Should not panic
_ = client.WAT() // Should not panic
_ = client.WLAN() // Should not panic
// Test tag service accessors
_ = client.PolicyTag() // Should not panic
_ = client.RFTag() // Should not panic
_ = client.SiteTag() // Should not panic
}