forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerMatchers.java
More file actions
66 lines (55 loc) · 2.36 KB
/
Copy pathDockerMatchers.java
File metadata and controls
66 lines (55 loc) · 2.36 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
package com.github.dockerjava.junit;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.core.DockerRule;
import com.github.dockerjava.core.RemoteApiVersion;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Description;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import java.util.ArrayList;
import java.util.List;
import static com.github.dockerjava.utils.TestUtils.getVersion;
/**
* @author Kanstantsin Shautsou
*/
public class DockerMatchers {
private DockerMatchers() {
}
public static MountedVolumes mountedVolumes(Matcher<? super List<Volume>> subMatcher) {
return new MountedVolumes(subMatcher, "Mounted volumes", "mountedVolumes");
}
public static class MountedVolumes extends FeatureMatcher<InspectContainerResponse, List<Volume>> {
public MountedVolumes(Matcher<? super List<Volume>> subMatcher, String featureDescription, String featureName) {
super(subMatcher, featureDescription, featureName);
}
@Override
public List<Volume> featureValueOf(InspectContainerResponse item) {
List<Volume> volumes = new ArrayList<>();
for (InspectContainerResponse.Mount mount : item.getMounts()) {
volumes.add(mount.getDestination());
}
return volumes;
}
}
public static Matcher<DockerRule> apiVersionGreater(final RemoteApiVersion version) {
return new CustomTypeSafeMatcher<DockerRule>("is greater") {
public boolean matchesSafely(DockerRule dockerRule) {
return getVersion(dockerRule.getClient()).isGreater(version);
}
};
}
public static Matcher<DockerRule> isGreaterOrEqual(final RemoteApiVersion version) {
return new CustomTypeSafeMatcher<DockerRule>("is greater or equal") {
public boolean matchesSafely(DockerRule dockerRule) {
return getVersion(dockerRule.getClient()).isGreaterOrEqual(version);
}
@Override
protected void describeMismatchSafely(DockerRule rule, Description mismatchDescription) {
mismatchDescription
.appendText(" was ")
.appendText(getVersion(rule.getClient()).toString());
}
};
}
}