@@ -18,6 +18,7 @@ package deviceplugin
18
18
import (
19
19
"context"
20
20
"encoding/json"
21
+ "strings"
21
22
"testing"
22
23
23
24
"github.com/intel/afxdp-plugins-for-kubernetes/constants"
@@ -57,6 +58,8 @@ func TestAllocate(t *testing.T) {
57
58
pm .ServerFactory = udsserver .NewFakeServerFactory ()
58
59
pm .BpfHandler = bpf .NewFakeHandler ()
59
60
61
+ envVar := constants .Devices .EnvVarList + strings .ToUpper (pm .Name )
62
+
60
63
testCases := []struct {
61
64
name string
62
65
containerRequests []* pluginapi.ContainerAllocateRequest
@@ -69,10 +72,10 @@ func TestAllocate(t *testing.T) {
69
72
},
70
73
expContainerResponses : []* pluginapi.ContainerAllocateResponse {
71
74
{
72
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_1" },
75
+ Envs : map [string ]string {envVar : "dev_1" },
73
76
Mounts : []* pluginapi.Mount {
74
77
{
75
- ContainerPath : constants .Uds .PodPath ,
78
+ ContainerPath : constants .Uds .PodPath + "dev_1" + constants . Uds . SockName ,
76
79
HostPath : "/tmp/fake-socket.sock" ,
77
80
ReadOnly : false ,
78
81
},
@@ -90,10 +93,20 @@ func TestAllocate(t *testing.T) {
90
93
},
91
94
expContainerResponses : []* pluginapi.ContainerAllocateResponse {
92
95
{
93
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_1 dev_2 dev_3" },
96
+ Envs : map [string ]string {envVar : "dev_1 dev_2 dev_3" },
94
97
Mounts : []* pluginapi.Mount {
95
98
{
96
- ContainerPath : constants .Uds .PodPath ,
99
+ ContainerPath : constants .Uds .PodPath + "dev_1" + constants .Uds .SockName ,
100
+ HostPath : "/tmp/fake-socket.sock" ,
101
+ ReadOnly : false ,
102
+ },
103
+ {
104
+ ContainerPath : constants .Uds .PodPath + "dev_2" + constants .Uds .SockName ,
105
+ HostPath : "/tmp/fake-socket.sock" ,
106
+ ReadOnly : false ,
107
+ },
108
+ {
109
+ ContainerPath : constants .Uds .PodPath + "dev_3" + constants .Uds .SockName ,
97
110
HostPath : "/tmp/fake-socket.sock" ,
98
111
ReadOnly : false ,
99
112
},
@@ -112,10 +125,10 @@ func TestAllocate(t *testing.T) {
112
125
},
113
126
expContainerResponses : []* pluginapi.ContainerAllocateResponse {
114
127
{
115
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_1" },
128
+ Envs : map [string ]string {envVar : "dev_1" },
116
129
Mounts : []* pluginapi.Mount {
117
130
{
118
- ContainerPath : constants .Uds .PodPath ,
131
+ ContainerPath : constants .Uds .PodPath + "dev_1" + constants . Uds . SockName ,
119
132
HostPath : "/tmp/fake-socket.sock" ,
120
133
ReadOnly : false ,
121
134
},
@@ -124,10 +137,10 @@ func TestAllocate(t *testing.T) {
124
137
Annotations : map [string ]string {},
125
138
},
126
139
{
127
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_2" },
140
+ Envs : map [string ]string {envVar : "dev_2" },
128
141
Mounts : []* pluginapi.Mount {
129
142
{
130
- ContainerPath : constants .Uds .PodPath ,
143
+ ContainerPath : constants .Uds .PodPath + "dev_2" + constants . Uds . SockName ,
131
144
HostPath : "/tmp/fake-socket.sock" ,
132
145
ReadOnly : false ,
133
146
},
@@ -146,10 +159,20 @@ func TestAllocate(t *testing.T) {
146
159
},
147
160
expContainerResponses : []* pluginapi.ContainerAllocateResponse {
148
161
{
149
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_1 dev_2 dev_3" },
162
+ Envs : map [string ]string {envVar : "dev_1 dev_2 dev_3" },
150
163
Mounts : []* pluginapi.Mount {
151
164
{
152
- ContainerPath : constants .Uds .PodPath ,
165
+ ContainerPath : constants .Uds .PodPath + "dev_1" + constants .Uds .SockName ,
166
+ HostPath : "/tmp/fake-socket.sock" ,
167
+ ReadOnly : false ,
168
+ },
169
+ {
170
+ ContainerPath : constants .Uds .PodPath + "dev_2" + constants .Uds .SockName ,
171
+ HostPath : "/tmp/fake-socket.sock" ,
172
+ ReadOnly : false ,
173
+ },
174
+ {
175
+ ContainerPath : constants .Uds .PodPath + "dev_3" + constants .Uds .SockName ,
153
176
HostPath : "/tmp/fake-socket.sock" ,
154
177
ReadOnly : false ,
155
178
},
@@ -158,10 +181,20 @@ func TestAllocate(t *testing.T) {
158
181
Annotations : map [string ]string {},
159
182
},
160
183
{
161
- Envs : map [string ]string {constants . Devices . EnvVarList : "dev_4 dev_5 dev_6" },
184
+ Envs : map [string ]string {envVar : "dev_4 dev_5 dev_6" },
162
185
Mounts : []* pluginapi.Mount {
163
186
{
164
- ContainerPath : constants .Uds .PodPath ,
187
+ ContainerPath : constants .Uds .PodPath + "dev_4" + constants .Uds .SockName ,
188
+ HostPath : "/tmp/fake-socket.sock" ,
189
+ ReadOnly : false ,
190
+ },
191
+ {
192
+ ContainerPath : constants .Uds .PodPath + "dev_5" + constants .Uds .SockName ,
193
+ HostPath : "/tmp/fake-socket.sock" ,
194
+ ReadOnly : false ,
195
+ },
196
+ {
197
+ ContainerPath : constants .Uds .PodPath + "dev_6" + constants .Uds .SockName ,
165
198
HostPath : "/tmp/fake-socket.sock" ,
166
199
ReadOnly : false ,
167
200
},
@@ -179,14 +212,8 @@ func TestAllocate(t *testing.T) {
179
212
},
180
213
expContainerResponses : []* pluginapi.ContainerAllocateResponse {
181
214
{
182
- Envs : map [string ]string {constants .Devices .EnvVarList : "" },
183
- Mounts : []* pluginapi.Mount {
184
- {
185
- ContainerPath : constants .Uds .PodPath ,
186
- HostPath : "/tmp/fake-socket.sock" ,
187
- ReadOnly : false ,
188
- },
189
- },
215
+ Envs : map [string ]string {envVar : "" },
216
+ Mounts : []* pluginapi.Mount {},
190
217
Devices : []* pluginapi.DeviceSpec {},
191
218
Annotations : map [string ]string {},
192
219
},
0 commit comments