31
31
import org .junit .Assume ;
32
32
33
33
import java .io .ByteArrayOutputStream ;
34
+ import java .io .File ;
34
35
import java .io .IOException ;
35
36
import java .util .Arrays ;
36
37
import java .util .List ;
39
40
import java .util .regex .Matcher ;
40
41
import java .util .regex .Pattern ;
41
42
42
- import org .hamcrest .Matchers ;
43
43
import org .jenkinsci .plugins .docker .commons .tools .DockerTool ;
44
44
45
45
/**
@@ -58,33 +58,20 @@ public class DockerTestUtil {
58
58
"10.0.26100.2605" // 2025
59
59
);
60
60
61
+ public enum DockerOsMode {
62
+ LINUX ,
63
+ WINDOWS
64
+ }
61
65
62
66
public static void assumeDocker () throws Exception {
63
- assumeDocker (new VersionNumber (DEFAULT_MINIMUM_VERSION ));
67
+ assumeDocker (DockerOsMode . LINUX , new VersionNumber (DEFAULT_MINIMUM_VERSION ));
64
68
}
65
-
66
- public static void assumeDocker (VersionNumber minimumVersion ) throws Exception {
67
- Launcher .LocalLauncher localLauncher = new Launcher .LocalLauncher (StreamTaskListener .NULL );
68
- try {
69
- int status = localLauncher
70
- .launch ()
71
- .cmds (DockerTool .getExecutable (null , null , null , null ), "ps" )
72
- .start ()
73
- .joinWithTimeout (DockerClient .CLIENT_TIMEOUT , TimeUnit .SECONDS , localLauncher .getListener ());
74
- Assume .assumeTrue ("Docker working" , status == 0 );
75
- } catch (IOException x ) {
76
- Assume .assumeNoException ("have Docker installed" , x );
77
- }
78
- DockerClient dockerClient = new DockerClient (localLauncher , null , null );
79
- Assume .assumeFalse ("Docker version not < " + minimumVersion .toString (), dockerClient .version ().isOlderThan (minimumVersion ));
69
+
70
+ public static void assumeDocker (DockerOsMode osMode ) throws Exception {
71
+ assumeDocker (osMode , new VersionNumber (DEFAULT_MINIMUM_VERSION ));
80
72
}
81
73
82
- /**
83
- * Used to assume docker Windows is running in a particular os mode
84
- * @param os The os [windows, linux]
85
- * @throws Exception
86
- */
87
- public static void assumeDockerServerOSMode (String os ) throws Exception {
74
+ public static void assumeDocker (DockerOsMode osMode , VersionNumber minimumVersion ) throws Exception {
88
75
Launcher .LocalLauncher localLauncher = new Launcher .LocalLauncher (StreamTaskListener .NULL );
89
76
try {
90
77
ByteArrayOutputStream out = new ByteArrayOutputStream ();
@@ -94,11 +81,14 @@ public static void assumeDockerServerOSMode(String os) throws Exception {
94
81
.stdout (out )
95
82
.start ()
96
83
.joinWithTimeout (DockerClient .CLIENT_TIMEOUT , TimeUnit .SECONDS , localLauncher .getListener ());
84
+ DockerOsMode cmdOsMode = DockerOsMode .valueOf (out .toString ().trim ().toUpperCase ());
97
85
Assume .assumeTrue ("Docker working" , status == 0 );
98
- Assume .assumeThat ("Docker running in " + os + " mode" , out . toString (). trim (), Matchers . equalToIgnoringCase ( os ) );
86
+ Assume .assumeTrue ("Docker os mode " + osMode , osMode == cmdOsMode );
99
87
} catch (IOException x ) {
100
- Assume .assumeNoException ("Docker retrieve OS " , x );
88
+ Assume .assumeNoException ("have Docker installed " , x );
101
89
}
90
+ DockerClient dockerClient = new DockerClient (localLauncher , null , null );
91
+ Assume .assumeFalse ("Docker version not < " + minimumVersion .toString (), dockerClient .version ().isOlderThan (minimumVersion ));
102
92
}
103
93
104
94
public static void assumeWindows () throws Exception {
@@ -109,6 +99,10 @@ public static void assumeNotWindows() throws Exception {
109
99
Assume .assumeFalse (System .getProperty ("os.name" ).toLowerCase ().contains ("windows" ));
110
100
}
111
101
102
+ public static void assumeDrive (char drive ) throws Exception {
103
+ Assume .assumeTrue (new File (drive + ":/" ).exists ());
104
+ }
105
+
112
106
public static String getWindowsKernelVersion () throws Exception {
113
107
Launcher .LocalLauncher localLauncher = new Launcher .LocalLauncher (StreamTaskListener .NULL );
114
108
ByteArrayOutputStream out = new ByteArrayOutputStream ();
0 commit comments