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
117 lines (97 loc) · 4.08 KB
/
Copy pathBindTest.java
File metadata and controls
117 lines (97 loc) · 4.08 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
package com.github.dockerjava.api.model;
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.core.Is.is;
import org.testng.annotations.Test;
public class BindTest {
@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));
}
@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));
}
@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));
}
@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));
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));
}
@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));
}
@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));
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Error parsing Bind.*")
public void parseInvalidAccessMode() {
Bind.parse("/host:/container:xx");
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Error parsing Bind 'nonsense'")
public void parseInvalidInput() {
Bind.parse("nonsense");
}
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Error parsing Bind 'null'")
public void parseNull() {
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 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"));
}
}