浏览代码

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 8 年之前
父节点
当前提交
63904eb674
共有 2 个文件被更改,包括 12 次插入6 次删除
  1. 11 5
      integration-cli/docker_cli_logs_test.go
  2. 1 1
      pkg/tailfile/tailfile.go

+ 11 - 5
integration-cli/docker_cli_logs_test.go

@@ -117,22 +117,28 @@ func (s *DockerSuite) TestLogsTail(c *check.C) {
 	id := strings.TrimSpace(out)
 	id := strings.TrimSpace(out)
 	dockerCmd(c, "wait", id)
 	dockerCmd(c, "wait", id)
 
 
-	out, _ = dockerCmd(c, "logs", "--tail", "5", id)
-
+	out, _ = dockerCmd(c, "logs", "--tail", "0", id)
 	lines := strings.Split(out, "\n")
 	lines := strings.Split(out, "\n")
+	c.Assert(lines, checker.HasLen, 1)
 
 
+	out, _ = dockerCmd(c, "logs", "--tail", "5", id)
+	lines = strings.Split(out, "\n")
 	c.Assert(lines, checker.HasLen, 6)
 	c.Assert(lines, checker.HasLen, 6)
 
 
-	out, _ = dockerCmd(c, "logs", "--tail", "all", id)
+	out, _ = dockerCmd(c, "logs", "--tail", "99", id)
+	lines = strings.Split(out, "\n")
+	c.Assert(lines, checker.HasLen, 100)
 
 
+	out, _ = dockerCmd(c, "logs", "--tail", "all", id)
 	lines = strings.Split(out, "\n")
 	lines = strings.Split(out, "\n")
+	c.Assert(lines, checker.HasLen, testLen+1)
 
 
+	out, _ = dockerCmd(c, "logs", "--tail", "-1", id)
+	lines = strings.Split(out, "\n")
 	c.Assert(lines, checker.HasLen, testLen+1)
 	c.Assert(lines, checker.HasLen, testLen+1)
 
 
 	out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id)
 	out, _, _ = dockerCmdWithStdoutStderr(c, "logs", "--tail", "random", id)
-
 	lines = strings.Split(out, "\n")
 	lines = strings.Split(out, "\n")
-
 	c.Assert(lines, checker.HasLen, testLen+1)
 	c.Assert(lines, checker.HasLen, testLen+1)
 }
 }
 
 

+ 1 - 1
pkg/tailfile/tailfile.go

@@ -44,7 +44,7 @@ func TailFile(f io.ReadSeeker, n int) ([][]byte, error) {
 			break
 			break
 		} else {
 		} else {
 			b = make([]byte, blockSize)
 			b = make([]byte, blockSize)
-			if _, err := f.Seek(step, os.SEEK_END); err != nil {
+			if _, err := f.Seek(left, os.SEEK_SET); err != nil {
 				return nil, err
 				return nil, err
 			}
 			}
 			if _, err := f.Read(b); err != nil {
 			if _, err := f.Read(b); err != nil {