Skip to content

Commit 2645180

Browse files
kopcsoLevovar
kopcso
authored andcommitted
add unit TC to PopDevice function
1 parent 7ea6eb9 commit 2645180

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Diff for: pkg/danm/danm_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
)
6+
7+
var devicePool0 = "pool0"
8+
var devicePool1 = "pool1"
9+
10+
var allocatedDevices = make(map[string]*[]string)
11+
12+
func TestPopDevicePanic(t *testing.T) {
13+
defer func() {
14+
if r := recover(); r == nil {
15+
t.Errorf("Uninitialized map should expect error.")
16+
}
17+
}()
18+
19+
popDevice(devicePool0, allocatedDevices)
20+
}
21+
22+
func TestPopDevice(t *testing.T) {
23+
allocatedDevices[devicePool0] = &[]string{"device0"}
24+
allocatedDevices[devicePool1] = &[]string{"device1", "device2"}
25+
26+
device,err := popDevice(devicePool1, allocatedDevices)
27+
if device != "device2" || err != nil {
28+
t.Errorf("Received device or error does not match with expectation.")
29+
}
30+
device,err = popDevice(devicePool1, allocatedDevices)
31+
if device != "device1" || err != nil {
32+
t.Errorf("Received device or error does not match with expectation.")
33+
}
34+
device,err = popDevice(devicePool1, allocatedDevices)
35+
if device == "" && err == nil {
36+
t.Errorf("Empty pool should expect error.")
37+
}
38+
}

0 commit comments

Comments
 (0)