diff options
author | adrianvillin <avillin@cisco.com> | 2024-02-12 02:44:53 -0500 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-02-15 02:38:10 +0000 |
commit | 7c675471e87c72be272c078fd481844e4efa64d0 (patch) | |
tree | 0fe20b6de72178124750a7a8f92155bef4a7c815 /extras/hs-test/container.go | |
parent | 0215ef1010fbe41a72d57e7cddc4fb18dc3d53d2 (diff) |
hs-test: improved logging
- improved readability of some error messages
- printing container logs to stdout on test failure (last 20 lines)
Type: test
Change-Id: Idbb358bdd89aa7b1a6bdc9d96bf029d4c299ce64
Signed-off-by: adrianvillin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/container.go')
-rw-r--r-- | extras/hs-test/container.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/extras/hs-test/container.go b/extras/hs-test/container.go index 86f511c2b46..10b5933b17f 100644 --- a/extras/hs-test/container.go +++ b/extras/hs-test/container.go @@ -285,7 +285,7 @@ func (c *Container) exec(command string, arguments ...any) string { c.suite.T().Helper() c.suite.log(containerExecCommand) byteOutput, err := exechelper.CombinedOutput(containerExecCommand) - c.suite.assertNil(err) + c.suite.assertNil(err, err) return string(byteOutput) } @@ -324,12 +324,18 @@ func (c *Container) saveLogs() { f.Close() } -func (c *Container) log() string { - cmd := "docker logs " + c.name +// Outputs logs from docker containers. Set 'maxLines' to 0 to output the full log. +func (c *Container) log(maxLines int) (string, error) { + var cmd string + if maxLines == 0 { + cmd = "docker logs " + c.name + } else { + cmd = fmt.Sprintf("docker logs --tail %d %s", maxLines, c.name) + } + c.suite.log(cmd) o, err := exechelper.CombinedOutput(cmd) - c.suite.assertNil(err) - return string(o) + return string(o), err } func (c *Container) stop() error { @@ -346,14 +352,14 @@ func (c *Container) createConfig(targetConfigName string, templateName string, v template := template.Must(template.ParseFiles(templateName)) f, err := os.CreateTemp(logDir, "hst-config") - c.suite.assertNil(err) + c.suite.assertNil(err, err) defer os.Remove(f.Name()) err = template.Execute(f, values) - c.suite.assertNil(err) + c.suite.assertNil(err, err) err = f.Close() - c.suite.assertNil(err) + c.suite.assertNil(err, err) c.copy(f.Name(), targetConfigName) } |