forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBindTest.java
More file actions
317 lines (275 loc) · 12.3 KB
/
Copy pathBindTest.java
File metadata and controls
317 lines (275 loc) · 12.3 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
package com.github.dockerjava.api.model;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static com.github.dockerjava.api.model.AccessMode.ro;
import static com.github.dockerjava.api.model.AccessMode.rw;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
public class BindTest {
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Test
public void parseUsingDefaultAccessMode() {
Bind bind = Bind.parse("/host:/container");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteNoCopyWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,nocopy");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), is(true));
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteSharedWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,shared");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SHARED));
}
@Test
public void parseReadWriteSlaveWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,slave");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SLAVE));
}
@Test
public void parseReadWritePrivateWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,private");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.PRIVATE));
}
@Test
public void parseReadOnlyWindows() {
Bind bind = Bind.parse("C:\\host:/container:ro");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseSELOnlyWindows() {
Bind bind = Bind.parse("C:\\host:/container:Z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
bind = Bind.parse("C:\\host:/container:z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteSELWindows() {
Bind bind = Bind.parse("C:\\host:/container:rw,Z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadOnlySELWindows() {
Bind bind = Bind.parse("C:\\host:/container:ro,z");
assertThat(bind.getPath(), is("C:\\host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWrite() {
Bind bind = Bind.parse("/host:/container:rw");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteNoCopy() {
Bind bind = Bind.parse("/host:/container:rw,nocopy");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), is(true));
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteShared() {
Bind bind = Bind.parse("/host:/container:rw,shared");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SHARED));
}
@Test
public void parseReadWriteSlave() {
Bind bind = Bind.parse("/host:/container:rw,slave");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.SLAVE));
}
@Test
public void parseReadWritePrivate() {
Bind bind = Bind.parse("/host:/container:rw,private");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.PRIVATE));
}
@Test
public void parseReadOnly() {
Bind bind = Bind.parse("/host:/container:ro");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.none));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseSELOnly() {
Bind bind = Bind.parse("/host:/container:Z");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
bind = Bind.parse("/host:/container:z");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(AccessMode.DEFAULT));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadWriteSEL() {
Bind bind = Bind.parse("/host:/container:rw,Z");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(rw));
assertThat(bind.getSecMode(), is(SELContext.single));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseReadOnlySEL() {
Bind bind = Bind.parse("/host:/container:ro,z");
assertThat(bind.getPath(), is("/host"));
assertThat(bind.getVolume().getPath(), is("/container"));
assertThat(bind.getAccessMode(), is(ro));
assertThat(bind.getSecMode(), is(SELContext.shared));
assertThat(bind.getNoCopy(), nullValue());
assertThat(bind.getPropagationMode(), is(PropagationMode.DEFAULT_MODE));
}
@Test
public void parseInvalidAccessMode() {
expectedEx.expect(IllegalArgumentException.class);
expectedEx.expectMessage( "Error parsing Bind");
Bind.parse("/host:/container:xx");
}
@Test
public void parseInvalidInput() {
expectedEx.expect(IllegalArgumentException.class);
expectedEx.expectMessage("Error parsing Bind 'nonsense'");
Bind.parse("nonsense");
}
@Test
public void parseNull() {
expectedEx.expect(IllegalArgumentException.class);
expectedEx.expectMessage("Error parsing Bind 'null'");
Bind.parse(null);
}
@Test
public void toStringReadOnly() {
assertThat(Bind.parse("/host:/container:ro").toString(), is("/host:/container:ro"));
}
@Test
public void toStringReadWrite() {
assertThat(Bind.parse("/host:/container:rw").toString(), is("/host:/container:rw"));
}
@Test
public void toStringReadWriteNoCopy() {
assertThat(Bind.parse("/host:/container:rw,nocopy").toString(), is("/host:/container:rw,nocopy"));
}
@Test
public void toStringReadWriteShared() {
assertThat(Bind.parse("/host:/container:rw,shared").toString(), is("/host:/container:rw,shared"));
}
@Test
public void toStringReadWriteSlave() {
assertThat(Bind.parse("/host:/container:rw,slave").toString(), is("/host:/container:rw,slave"));
}
@Test
public void toStringReadWritePrivate() {
assertThat(Bind.parse("/host:/container:rw,private").toString(), is("/host:/container:rw,private"));
}
@Test
public void toStringDefaultAccessMode() {
assertThat(Bind.parse("/host:/container").toString(), is("/host:/container:rw"));
}
@Test
public void toStringReadOnlySEL() {
assertThat(Bind.parse("/host:/container:ro,Z").toString(), is("/host:/container:ro,Z"));
}
@Test
public void toStringReadWriteSEL() {
assertThat(Bind.parse("/host:/container:rw,z").toString(), is("/host:/container:rw,z"));
}
@Test
public void toStringDefaultSEL() {
assertThat(Bind.parse("/host:/container:Z").toString(), is("/host:/container:rw,Z"));
}
}