1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package sysfs
18
19 import (
20 "testing"
21
22 "github.com/google/go-cmp/cmp"
23 )
24
25 func TestSASDeviceClass(t *testing.T) {
26 fs, err := NewFS(sysTestFixtures)
27 if err != nil {
28 t.Fatal(err)
29 }
30
31 got, err := fs.SASDeviceClass()
32 if err != nil {
33 t.Fatal(err)
34 }
35
36 want := SASDeviceClass{
37 "end_device-11:0:0": {
38 Name: "end_device-11:0:0",
39 SASAddress: "0x5000ccab02009402",
40 BlockDevices: []string{"sdv"},
41 },
42 "end_device-11:0:1": {
43 Name: "end_device-11:0:1",
44 SASAddress: "0x5000cca26128b1f5",
45 BlockDevices: []string{"sdw"},
46 },
47 "end_device-11:0:2": {
48 Name: "end_device-11:0:2",
49 SASAddress: "0x5000ccab02009406",
50 BlockDevices: []string{"sdx"},
51 },
52 "end_device-11:2": {
53 Name: "end_device-11:2",
54 SASAddress: "0x5000cca0506b5f1d",
55 BlockDevices: []string{"sdp"},
56 },
57 "expander-11:0": {
58 Name: "expander-11:0",
59 SASAddress: "0x5000ccab0200947e",
60 SASPhys: []string{
61 "phy-11:0:10", "phy-11:0:11", "phy-11:0:12",
62 "phy-11:0:13", "phy-11:0:14", "phy-11:0:15",
63 "phy-11:0:2", "phy-11:0:4", "phy-11:0:6",
64 "phy-11:0:7", "phy-11:0:8", "phy-11:0:9",
65 },
66 SASPorts: []string{
67 "port-11:0:0", "port-11:0:1",
68 "port-11:0:2",
69 },
70 },
71 "expander-11:1": {
72 Name: "expander-11:1",
73 SASAddress: "0x5003048001e8967f",
74 },
75 }
76
77 if diff := cmp.Diff(want, got); diff != "" {
78 t.Fatalf("unexpected SASDevice class (-want +got):\n%s", diff)
79 }
80 }
81
82 func TestSASEndDeviceClass(t *testing.T) {
83 fs, err := NewFS(sysTestFixtures)
84 if err != nil {
85 t.Fatal(err)
86 }
87
88 got, err := fs.SASEndDeviceClass()
89 if err != nil {
90 t.Fatal(err)
91 }
92
93 want := SASDeviceClass{
94 "end_device-11:0:0": {
95 Name: "end_device-11:0:0",
96 SASAddress: "0x5000ccab02009402",
97 BlockDevices: []string{"sdv"},
98 },
99 "end_device-11:0:1": {
100 Name: "end_device-11:0:1",
101 SASAddress: "0x5000cca26128b1f5",
102 BlockDevices: []string{"sdw"},
103 },
104 "end_device-11:0:2": {
105 Name: "end_device-11:0:2",
106 SASAddress: "0x5000ccab02009406",
107 BlockDevices: []string{"sdx"},
108 },
109 "end_device-11:2": {
110 Name: "end_device-11:2",
111 SASAddress: "0x5000cca0506b5f1d",
112 BlockDevices: []string{"sdp"},
113 },
114 }
115
116 if diff := cmp.Diff(want, got); diff != "" {
117 t.Fatalf("unexpected SASDevice class (-want +got):\n%s", diff)
118 }
119 }
120
121 func TestSASExpanderClass(t *testing.T) {
122 fs, err := NewFS(sysTestFixtures)
123 if err != nil {
124 t.Fatal(err)
125 }
126
127 got, err := fs.SASExpanderClass()
128 if err != nil {
129 t.Fatal(err)
130 }
131
132 want := SASDeviceClass{
133 "expander-11:0": {
134 Name: "expander-11:0",
135 SASAddress: "0x5000ccab0200947e",
136 SASPhys: []string{
137 "phy-11:0:10", "phy-11:0:11", "phy-11:0:12",
138 "phy-11:0:13", "phy-11:0:14", "phy-11:0:15",
139 "phy-11:0:2", "phy-11:0:4", "phy-11:0:6",
140 "phy-11:0:7", "phy-11:0:8", "phy-11:0:9",
141 },
142 SASPorts: []string{
143 "port-11:0:0", "port-11:0:1",
144 "port-11:0:2",
145 },
146 },
147 "expander-11:1": {
148 Name: "expander-11:1",
149 SASAddress: "0x5003048001e8967f",
150 },
151 }
152
153 if diff := cmp.Diff(want, got); diff != "" {
154 t.Fatalf("unexpected SASDevice class (-want +got):\n%s", diff)
155 }
156 }
157
158 func TestSASDeviceGetByName(t *testing.T) {
159 fs, err := NewFS(sysTestFixtures)
160 if err != nil {
161 t.Fatal(err)
162 }
163
164 dc, err := fs.SASDeviceClass()
165 if err != nil {
166 t.Fatal(err)
167 }
168
169 want := "expander-11:0"
170 got := dc.GetByName("expander-11:0").Name
171 if diff := cmp.Diff(want, got); diff != "" {
172 t.Fatalf("unexpected SASDevice name (-want +got):\n%s", diff)
173 }
174
175
176 got2 := dc.GetByName("expander-15")
177 if got2 != nil {
178 t.Fatalf("unexpected GetByName response: got %v want nil", got2)
179 }
180 }
181
182 func TestSASDeviceGetByPhy(t *testing.T) {
183 fs, err := NewFS(sysTestFixtures)
184 if err != nil {
185 t.Fatal(err)
186 }
187
188 dc, err := fs.SASDeviceClass()
189 if err != nil {
190 t.Fatal(err)
191 }
192
193 want := "expander-11:0"
194 got := dc.GetByPhy("phy-11:0:11").Name
195 if diff := cmp.Diff(want, got); diff != "" {
196 t.Fatalf("unexpected SASDevice class (-want +got):\n%s", diff)
197 }
198
199
200 got2 := dc.GetByPhy("phy-12:0")
201 if got2 != nil {
202 t.Fatalf("unexpected GetByPhy response: got %v want nil", got2)
203 }
204 }
205
206 func TestSASDeviceGetByPort(t *testing.T) {
207 fs, err := NewFS(sysTestFixtures)
208 if err != nil {
209 t.Fatal(err)
210 }
211
212 dc, err := fs.SASDeviceClass()
213 if err != nil {
214 t.Fatal(err)
215 }
216
217 want := "expander-11:0"
218 got := dc.GetByPort("port-11:0:0").Name
219 if diff := cmp.Diff(want, got); diff != "" {
220 t.Fatalf("unexpected SASDevice class (-want +got):\n%s", diff)
221 }
222
223
224 got2 := dc.GetByPort("port-12:0")
225 if got2 != nil {
226 t.Fatalf("unexpected GetByPhy response: got %v want nil", got2)
227 }
228 }
229
View as plain text