mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Tidy duplicate log tests
Some log tests were duplicated, and some didn't need to be repeated for every driver. Also, added some comments Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -29,7 +29,6 @@ func (c *Container) ReadLog(ctx context.Context, options *logs.LogOptions, logCh
|
|||||||
case define.NoLogging:
|
case define.NoLogging:
|
||||||
return errors.Wrapf(define.ErrNoLogs, "this container is using the 'none' log driver, cannot read logs")
|
return errors.Wrapf(define.ErrNoLogs, "this container is using the 'none' log driver, cannot read logs")
|
||||||
case define.JournaldLogging:
|
case define.JournaldLogging:
|
||||||
// TODO Skip sending logs until journald logs can be read
|
|
||||||
return c.readFromJournal(ctx, options, logChannel)
|
return c.readFromJournal(ctx, options, logChannel)
|
||||||
case define.JSONLogging:
|
case define.JSONLogging:
|
||||||
// TODO provide a separate implementation of this when Conmon
|
// TODO provide a separate implementation of this when Conmon
|
||||||
|
@ -52,6 +52,7 @@ func (c *Container) readFromJournal(ctx context.Context, options *logs.LogOption
|
|||||||
if time.Now().Before(options.Since) {
|
if time.Now().Before(options.Since) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// coreos/go-systemd/sdjournal expects a negative time.Duration for times in the past
|
||||||
config.Since = -time.Since(options.Since)
|
config.Since = -time.Since(options.Since)
|
||||||
}
|
}
|
||||||
config.Matches = append(config.Matches, journal.Match{
|
config.Matches = append(config.Matches, journal.Match{
|
||||||
|
@ -37,16 +37,18 @@ var _ = Describe("Podman logs", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
for _, log := range []string{"k8s-file", "journald", "json-file"} {
|
for _, log := range []string{"k8s-file", "journald", "json-file"} {
|
||||||
|
|
||||||
It("all lines: "+log, func() {
|
It("all lines: "+log, func() {
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
||||||
logc.WaitWithDefaultTimeout()
|
logc.WaitWithDefaultTimeout()
|
||||||
Expect(logc).To(Exit(0))
|
Expect(logc).To(Exit(0))
|
||||||
|
|
||||||
cid := logc.OutputToString()
|
cid := logc.OutputToString()
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", cid})
|
results := podmanTest.Podman([]string{"logs", cid})
|
||||||
results.WaitWithDefaultTimeout()
|
results.WaitWithDefaultTimeout()
|
||||||
Expect(results).To(Exit(0))
|
Expect(results).To(Exit(0))
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||||
|
Expect(results.OutputToString()).To(Equal("podman podman podman"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("tail two lines: "+log, func() {
|
It("tail two lines: "+log, func() {
|
||||||
@ -73,6 +75,18 @@ var _ = Describe("Podman logs", func() {
|
|||||||
Expect(len(results.OutputToStringArray())).To(Equal(0))
|
Expect(len(results.OutputToStringArray())).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("tail 99 lines: "+log, func() {
|
||||||
|
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
||||||
|
logc.WaitWithDefaultTimeout()
|
||||||
|
Expect(logc).To(Exit(0))
|
||||||
|
cid := logc.OutputToString()
|
||||||
|
|
||||||
|
results := podmanTest.Podman([]string{"logs", "--tail", "99", cid})
|
||||||
|
results.WaitWithDefaultTimeout()
|
||||||
|
Expect(results).To(Exit(0))
|
||||||
|
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
||||||
|
})
|
||||||
|
|
||||||
It("tail 800 lines: "+log, func() {
|
It("tail 800 lines: "+log, func() {
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "i=1; while [ \"$i\" -ne 1000 ]; do echo \"line $i\"; i=$((i + 1)); done"})
|
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "i=1; while [ \"$i\" -ne 1000 ]; do echo \"line $i\"; i=$((i + 1)); done"})
|
||||||
logc.WaitWithDefaultTimeout()
|
logc.WaitWithDefaultTimeout()
|
||||||
@ -158,78 +172,6 @@ var _ = Describe("Podman logs", func() {
|
|||||||
Expect(results).To(Exit(0))
|
Expect(results).To(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("for container: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
|
||||||
Expect(results.OutputToString()).To(Equal("podman podman podman"))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("tail two lines: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--tail", "2", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(2))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("tail 99 lines: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--tail", "99", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("tail 2 lines with timestamps: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--tail", "2", "-t", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(2))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("since time 2017-08-07: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--since", "2017-08-07T10:10:09.056611202-04:00", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("with duration 10m: "+log, func() {
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "-dt", ALPINE, "sh", "-c", "echo podman; echo podman; echo podman"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
cid := logc.OutputToString()
|
|
||||||
|
|
||||||
results := podmanTest.Podman([]string{"logs", "--since", "10m", cid})
|
|
||||||
results.WaitWithDefaultTimeout()
|
|
||||||
Expect(results).To(Exit(0))
|
|
||||||
Expect(len(results.OutputToStringArray())).To(Equal(3))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("streaming output: "+log, func() {
|
It("streaming output: "+log, func() {
|
||||||
containerName := "logs-f-rm"
|
containerName := "logs-f-rm"
|
||||||
|
|
||||||
@ -259,17 +201,6 @@ var _ = Describe("Podman logs", func() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman logs with log-driver=none errors: "+log, func() {
|
|
||||||
ctrName := "logsctr"
|
|
||||||
logc := podmanTest.Podman([]string{"run", "--log-driver", log, "--name", ctrName, "-d", "--log-driver", "none", ALPINE, "top"})
|
|
||||||
logc.WaitWithDefaultTimeout()
|
|
||||||
Expect(logc).To(Exit(0))
|
|
||||||
|
|
||||||
logs := podmanTest.Podman([]string{"logs", "-f", ctrName})
|
|
||||||
logs.WaitWithDefaultTimeout()
|
|
||||||
Expect(logs).To(Not(Exit(0)))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("follow output stopped container: "+log, func() {
|
It("follow output stopped container: "+log, func() {
|
||||||
containerName := "logs-f"
|
containerName := "logs-f"
|
||||||
|
|
||||||
@ -373,4 +304,15 @@ var _ = Describe("Podman logs", func() {
|
|||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
Expect(string(out)).To(ContainSubstring(containerName))
|
Expect(string(out)).To(ContainSubstring(containerName))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman logs with log-driver=none errors", func() {
|
||||||
|
ctrName := "logsctr"
|
||||||
|
logc := podmanTest.Podman([]string{"run", "--name", ctrName, "-d", "--log-driver", "none", ALPINE, "top"})
|
||||||
|
logc.WaitWithDefaultTimeout()
|
||||||
|
Expect(logc).To(Exit(0))
|
||||||
|
|
||||||
|
logs := podmanTest.Podman([]string{"logs", "-f", ctrName})
|
||||||
|
logs.WaitWithDefaultTimeout()
|
||||||
|
Expect(logs).To(Not(Exit(0)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user