From fa9658cbfaa94fd5d0425041404e498c01db1aa3 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 6 Feb 2018 09:07:51 -0600 Subject: podman logs: fix tailing Fix issues with tailing of container logs as described in issue #16. Also add in the ability to use a duration or known time stamp formats for the --since flag. Signed-off-by: baude Closes: #317 Approved by: mheon --- test/e2e/logs_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index d8fc440c0..74e31016c 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -28,33 +28,82 @@ var _ = Describe("Podman logs", func() { }) + //sudo bin/podman run -it --rm fedora-minimal bash -c 'for a in `seq 5`; do echo hello; done' It("podman logs for container", func() { - _, ec, cid := podmanTest.RunLsContainer("") - Expect(ec).To(Equal(0)) + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() results := podmanTest.Podman([]string{"logs", cid}) results.WaitWithDefaultTimeout() Expect(results.ExitCode()).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(4)) }) - It("podman logs tail three lines", func() { - Skip("Tail is not working correctly") - _, ec, cid := podmanTest.RunLsContainer("") - Expect(ec).To(Equal(0)) + It("podman logs tail two lines", func() { + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() - results := podmanTest.Podman([]string{"logs", "--tail", "3", cid}) + results := podmanTest.Podman([]string{"logs", "--tail", "2", cid}) results.WaitWithDefaultTimeout() Expect(results.ExitCode()).To(Equal(0)) Expect(len(results.OutputToStringArray())).To(Equal(3)) }) - It("podman logs since a given time", func() { - _, ec, cid := podmanTest.RunLsContainer("") - Expect(ec).To(Equal(0)) + It("podman logs tail 99 lines", func() { + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() + + results := podmanTest.Podman([]string{"logs", "--tail", "99", cid}) + results.WaitWithDefaultTimeout() + Expect(results.ExitCode()).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(4)) + }) + + It("podman logs tail 2 lines with timestamps", func() { + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() + + results := podmanTest.Podman([]string{"logs", "--tail", "2", "-t", cid}) + results.WaitWithDefaultTimeout() + Expect(results.ExitCode()).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(3)) + }) + + It("podman logs latest with since time", func() { + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() results := podmanTest.Podman([]string{"logs", "--since", "2017-08-07T10:10:09.056611202-04:00", cid}) results.WaitWithDefaultTimeout() Expect(results.ExitCode()).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(4)) }) + It("podman logs latest with since duration", func() { + podmanTest.RestoreArtifact(fedoraMinimal) + logc := podmanTest.Podman([]string{"run", "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"}) + logc.WaitWithDefaultTimeout() + Expect(logc.ExitCode()).To(Equal(0)) + cid := logc.OutputToString() + + results := podmanTest.Podman([]string{"logs", "--since", "10m", cid}) + results.WaitWithDefaultTimeout() + Expect(results.ExitCode()).To(Equal(0)) + Expect(len(results.OutputToStringArray())).To(Equal(4)) + }) }) -- cgit v1.2.3-54-g00ecf