forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameReaderTest.java
More file actions
61 lines (47 loc) · 1.71 KB
/
Copy pathFrameReaderTest.java
File metadata and controls
61 lines (47 loc) · 1.71 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
package com.github.dockerjava.core.command;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Test;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.StreamType;
public class FrameReaderTest {
public static final int HEADER_SIZE = 8;
private final List<Integer> bytes = new ArrayList<>();
private final InputStream inputStream = new InputStream() {
@Override
public int read() throws IOException {
return bytes.isEmpty() ? -1 : bytes.remove(0);
}
};
private final FrameReader frameReader = new FrameReader(inputStream);
@Test
public void endOfStreamReturnsNull() throws Exception {
assertNull(nextFrame());
}
@Test
public void stdInBytesFrameReturnsFrame() throws Exception {
assertEquals(nextFrame(0, 0, 0, 0, 0, 0, 0, 0), new Frame(StreamType.STDIN, new byte[0]));
}
private Frame nextFrame(int... bytes) throws IOException {
setBytes(bytes);
return frameReader.readFrame();
}
@Test
public void stdOutBytesFrameReturnsFrame() throws Exception {
assertEquals(nextFrame(1, 0, 0, 0, 0, 0, 0, 0), new Frame(StreamType.STDOUT, new byte[0]));
}
@Test
public void stdErrBytesFrameReturnsFrame() throws Exception {
assertEquals(nextFrame(2, 0, 0, 0, 0, 0, 0, 0), new Frame(StreamType.STDERR, new byte[0]));
}
private void setBytes(int... bytes) {
this.bytes.clear();
for (int aByte : bytes) {
this.bytes.add(aByte);
}
}
}