22
33import org .testng .annotations .Test ;
44
5+ import java .util .ArrayList ;
6+ import java .util .Arrays ;
7+ import java .util .Collections ;
8+ import java .util .HashMap ;
9+ import java .util .LinkedHashMap ;
10+ import java .util .List ;
11+ import java .util .Map ;
12+
13+ import static junit .framework .Assert .fail ;
514import static org .hamcrest .MatcherAssert .assertThat ;
15+ import static org .hamcrest .Matchers .contains ;
16+ import static org .hamcrest .Matchers .containsString ;
617import static org .hamcrest .Matchers .equalTo ;
18+ import static org .hamcrest .Matchers .is ;
719
820/**
921 * @author Kanstantsin Shautsou
1022 */
1123public class DeviceTest {
24+
25+ public static List <String > validPaths = Arrays .asList (
26+ "/home" ,
27+ "/home:/home" ,
28+ "/home:/something/else" ,
29+ "/with space" ,
30+ "/home:/with space" ,
31+ "relative:/absolute-path" ,
32+ "hostPath:/containerPath:r" ,
33+ "/hostPath:/containerPath:rw" ,
34+ "/hostPath:/containerPath:mrw"
35+ );
36+
37+ public static HashMap <String , String > badPaths = new LinkedHashMap <String , String >() {{
38+ put ("" , "bad format for path: " );
39+ // TODO implement ValidatePath
40+ // put("./", "./ is not an absolute path");
41+ // put("../", "../ is not an absolute path");
42+ // put("/:../", "../ is not an absolute path");
43+ // put("/:path", "path is not an absolute path");
44+ // put(":", "bad format for path: :");
45+ // put("/tmp:", " is not an absolute path");
46+ // put(":test", "bad format for path: :test");
47+ // put(":/test", "bad format for path: :/test");
48+ // put("tmp:", " is not an absolute path");
49+ // put(":test:", "bad format for path: :test:");
50+ // put("::", "bad format for path: ::");
51+ // put(":::", "bad format for path: :::");
52+ // put("/tmp:::", "bad format for path: /tmp:::");
53+ // put(":/tmp::", "bad format for path: :/tmp::");
54+ // put("path:ro", "ro is not an absolute path");
55+ // put("path:rr", "rr is not an absolute path");
56+ put ("a:/b:ro" , "bad mode specified: ro" );
57+ put ("a:/b:rr" , "bad mode specified: rr" );
58+ }};
59+
1260 @ Test
1361 public void testParse () throws Exception {
1462 assertThat (Device .parse ("/dev/sda:/dev/xvdc:r" ),
@@ -24,4 +72,24 @@ public void testParse() throws Exception {
2472 equalTo (new Device ("rw" , "/something" , "/dev/snd" )));
2573
2674 }
75+
76+ @ Test
77+ public void testParseBadPaths () {
78+ for (Map .Entry <String , String > entry : badPaths .entrySet ()) {
79+ final String deviceStr = entry .getKey ();
80+ try {
81+ Device .parse (deviceStr );
82+ fail ("Should fail because: " + entry .getValue () + " '" + deviceStr + "'" );
83+ } catch (IllegalArgumentException ex ) {
84+ assertThat (ex .getMessage (), containsString ("Invalid device specification:" ));
85+ }
86+ }
87+ }
88+
89+ @ Test
90+ public void testParseValidPaths () {
91+ for (String path : validPaths ) {
92+ Device .parse (path );
93+ }
94+ }
2795}
0 commit comments