diff options
author | Aditya Rajan <arajan@redhat.com> | 2021-09-09 15:39:13 +0530 |
---|---|---|
committer | Aditya Rajan <arajan@redhat.com> | 2021-09-09 16:37:24 +0530 |
commit | 6888b061d06a699772921aaf6c57f4bd6c95d1c6 (patch) | |
tree | 8ac85cb3d13bdde70aa2640dfd7b74eb0227cb60 | |
parent | 2b41c4d667d3bc830e4fef629c6fc24d5cf8ae1e (diff) | |
download | podman-6888b061d06a699772921aaf6c57f4bd6c95d1c6.tar.gz podman-6888b061d06a699772921aaf6c57f4bd6c95d1c6.tar.bz2 podman-6888b061d06a699772921aaf6c57f4bd6c95d1c6.zip |
inspect: printTmpl must Flush writer
Flush should be called after the last call to Write to ensure that any data buffered in the Writer is written to output.
Any incomplete escape sequence at the end is considered complete for formatting purposes.
Signed-off-by: Aditya Rajan <arajan@redhat.com>
-rw-r--r-- | cmd/podman/inspect/inspect.go | 4 | ||||
-rw-r--r-- | cmd/podman/pods/inspect.go | 4 | ||||
-rw-r--r-- | test/e2e/build/envwithtab/Dockerfile | 3 | ||||
-rw-r--r-- | test/e2e/inspect_test.go | 18 |
4 files changed, 27 insertions, 2 deletions
diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go index bd3060882..4c7fa33a4 100644 --- a/cmd/podman/inspect/inspect.go +++ b/cmd/podman/inspect/inspect.go @@ -254,7 +254,9 @@ func printTmpl(typ, row string, data []interface{}) error { if err != nil { return err } - return t.Execute(w, data) + err = t.Execute(w, data) + w.Flush() + return err } func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]interface{}, []error, error) { diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go index 4bb88f48a..96eaec3b9 100644 --- a/cmd/podman/pods/inspect.go +++ b/cmd/podman/pods/inspect.go @@ -80,5 +80,7 @@ func inspect(cmd *cobra.Command, args []string) error { if err != nil { return err } - return t.Execute(w, *responses) + err = t.Execute(w, *responses) + w.Flush() + return err } diff --git a/test/e2e/build/envwithtab/Dockerfile b/test/e2e/build/envwithtab/Dockerfile new file mode 100644 index 000000000..0d8480c04 --- /dev/null +++ b/test/e2e/build/envwithtab/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine + +ENV TEST=" t" diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 89859e74f..59615d009 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -50,6 +50,24 @@ var _ = Describe("Podman inspect", func() { Expect(session).To(ExitWithError()) }) + It("podman inspect filter should work if result contains tab", func() { + session := podmanTest.Podman([]string{"build", "--tag", "envwithtab", "build/envwithtab"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + + // Verify that OS and Arch are being set + inspect := podmanTest.Podman([]string{"inspect", "-f", "{{ .Config.Env }}", "envwithtab"}) + inspect.WaitWithDefaultTimeout() + Expect(inspect).Should(Exit(0)) + // output should not be empty + // test validates fix for https://github.com/containers/podman/issues/8785 + Expect(strings.Contains(inspect.OutputToString(), "TEST")) + + session = podmanTest.Podman([]string{"rmi", "envwithtab"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + }) + It("podman inspect with GO format", func() { session := podmanTest.Podman([]string{"inspect", "--format", "{{.ID}}", ALPINE}) session.WaitWithDefaultTimeout() |