Browse code

Change reading order of tailfile

change reading order from beginning at the end to beginning at a buffer start
added intergration tests for boundary cases
Removed whitespace
Signed-off-by: Shayne Wang <shaynexwang@gmail.com>

Shayne Wang authored on 2016/11/10 12:16:47
Showing 2 changed files
... ...
@@ -117,22 +117,28 @@ func (s *DockerSuite) TestLogsTail(c *check.C) {
117 117
 	id := strings.TrimSpace(out)
118 118
 	dockerCmd(c, "wait", id)
119 119
 
120
-	out, _ = dockerCmd(c, "logs", "--tail", "5", id)
121
-
120
+	out, _ = dockerCmd(c, "logs", "--tail", "0", id)
122 121
 	lines := strings.Split(out, "\n")
122
+	c.Assert(lines, checker.HasLen, 1)
123 123
 
124
+	out, _ = dockerCmd(c, "logs", "--tail", "5", id)
125
+	lines = strings.Split(out, "\n")
124 126
 	c.Assert(lines, checker.HasLen, 6)
125 127
 
126
-	out, _ = dockerCmd(c, "logs", "--tail", "all", id)
128
+	out, _ = dockerCmd(c, "logs", "--tail", "99", id)
129
+	lines = strings.Split(out, "\n")
130
+	c.Assert(lines, checker.HasLen, 100)
127 131
 
132
+	out, _ = dockerCmd(c, "logs", "--tail", "all", id)
128 133
 	lines = strings.Split(out, "\n")
134
+	c.Assert(lines, checker.HasLen, testLen+1)
129 135
 
136
+	out, _ = dockerCmd(c, "logs", "--tail", "-1", id)
137
+	lines = strings.Split(out, "\n")
130 138
 	c.Assert(lines, checker.HasLen, testLen+1)
131 139
 
132 140
 	out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id)
133
-
134 141
 	lines = strings.Split(out, "\n")
135
-
136 142
 	c.Assert(lines, checker.HasLen, testLen+1)
137 143
 }
138 144
 
... ...
@@ -44,7 +44,7 @@ func TailFile(f io.ReadSeeker, n int) ([][]byte, error) {
44 44
 			break
45 45
 		} else {
46 46
 			b = make([]byte, blockSize)
47
-			if _, err := f.Seek(step, os.SEEK_END); err != nil {
47
+			if _, err := f.Seek(left, os.SEEK_SET); err != nil {
48 48
 				return nil, err
49 49
 			}
50 50
 			if _, err := f.Read(b); err != nil {