File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments