diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-05-13 12:30:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-13 12:30:14 -0700 |
commit | 71f66f03c5dcf8ab65c741e64c60ce12b01218a8 (patch) | |
tree | 3000cb5cb03f019dd8b18386330552ca109e2612 /pkg/bindings/test/attach_test.go | |
parent | 886b2cc4b10c32611b45da983fa9d1318d38356a (diff) | |
parent | b6113e2b9ea8f397e345a09335c26f953994c6f4 (diff) | |
download | podman-71f66f03c5dcf8ab65c741e64c60ce12b01218a8.tar.gz podman-71f66f03c5dcf8ab65c741e64c60ce12b01218a8.tar.bz2 podman-71f66f03c5dcf8ab65c741e64c60ce12b01218a8.zip |
Merge pull request #6203 from jwhonce/wip/attach
V2 attach bindings and test
Diffstat (limited to 'pkg/bindings/test/attach_test.go')
-rw-r--r-- | pkg/bindings/test/attach_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/bindings/test/attach_test.go b/pkg/bindings/test/attach_test.go new file mode 100644 index 000000000..8e89ff8ff --- /dev/null +++ b/pkg/bindings/test/attach_test.go @@ -0,0 +1,63 @@ +package test_bindings + +import ( + "bytes" + "time" + + "github.com/containers/libpod/pkg/bindings" + "github.com/containers/libpod/pkg/bindings/containers" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" +) + +var _ = Describe("Podman containers attach", func() { + var ( + bt *bindingTest + s *gexec.Session + ) + + BeforeEach(func() { + bt = newBindingTest() + bt.RestoreImagesFromCache() + s = bt.startAPIService() + time.Sleep(1 * time.Second) + err := bt.NewConnection() + Expect(err).ShouldNot(HaveOccurred()) + }) + + AfterEach(func() { + s.Kill() + bt.cleanup() + }) + + It("attach", func() { + name := "TopAttachTest" + id, err := bt.RunTopContainer(&name, nil, nil) + Expect(err).ShouldNot(HaveOccurred()) + + tickTock := time.NewTimer(2 * time.Second) + go func() { + <-tickTock.C + timeout := uint(5) + err := containers.Stop(bt.conn, id, &timeout) + if err != nil { + GinkgoWriter.Write([]byte(err.Error())) + } + }() + + stdout := &bytes.Buffer{} + stderr := &bytes.Buffer{} + go func() { + defer GinkgoRecover() + + err := containers.Attach(bt.conn, id, nil, &bindings.PTrue, &bindings.PTrue, &bindings.PTrue, stdout, stderr) + Expect(err).ShouldNot(HaveOccurred()) + }() + + time.Sleep(5 * time.Second) + + // First character/First line of top output + Expect(stdout.String()).Should(ContainSubstring("Mem: ")) + }) +}) |