summaryrefslogtreecommitdiff
path: root/pkg/bindings/test
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings/test')
-rw-r--r--pkg/bindings/test/containers_test.go34
-rw-r--r--pkg/bindings/test/exec_test.go77
-rw-r--r--pkg/bindings/test/images_test.go65
-rw-r--r--pkg/bindings/test/pods_test.go95
4 files changed, 228 insertions, 43 deletions
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index f5465c803..a31181958 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -1,12 +1,12 @@
package test_bindings
import (
- "github.com/containers/libpod/libpod/define"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/specgen"
@@ -34,7 +34,7 @@ var _ = Describe("Podman containers ", func() {
AfterEach(func() {
s.Kill()
- //bt.cleanup()
+ bt.cleanup()
})
It("podman pause a bogus container", func() {
@@ -380,4 +380,34 @@ var _ = Describe("Podman containers ", func() {
_, err = time.Parse(time.RFC1123Z, o)
Expect(err).To(BeNil())
})
+
+ It("podman top", func() {
+ var name = "top"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+
+ // By name
+ _, err = containers.Top(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+
+ // By id
+ _, err = containers.Top(bt.conn, cid, nil)
+ Expect(err).To(BeNil())
+
+ // With descriptors
+ output, err := containers.Top(bt.conn, cid, []string{"user,pid,hpid"})
+ Expect(err).To(BeNil())
+ header := strings.Split(output[0], "\t")
+ for _, d := range []string{"USER", "PID", "HPID"} {
+ Expect(d).To(BeElementOf(header))
+ }
+
+ // With bogus ID
+ _, err = containers.Top(bt.conn, "IdoNotExist", nil)
+ Expect(err).ToNot(BeNil())
+
+ // With bogus descriptors
+ _, err = containers.Top(bt.conn, cid, []string{"Me,Neither"})
+ Expect(err).To(BeNil())
+ })
})
diff --git a/pkg/bindings/test/exec_test.go b/pkg/bindings/test/exec_test.go
new file mode 100644
index 000000000..1ef2197b6
--- /dev/null
+++ b/pkg/bindings/test/exec_test.go
@@ -0,0 +1,77 @@
+package test_bindings
+
+import (
+ "time"
+
+ "github.com/containers/libpod/pkg/api/handlers"
+ "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 exec", 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).To(BeNil())
+ })
+
+ AfterEach(func() {
+ s.Kill()
+ bt.cleanup()
+ })
+
+ It("Podman exec create makes an exec session", func() {
+ name := "testCtr"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+
+ execConfig := new(handlers.ExecCreateConfig)
+ execConfig.Cmd = []string{"echo", "hello world"}
+
+ sessionID, err := containers.ExecCreate(bt.conn, name, execConfig)
+ Expect(err).To(BeNil())
+ Expect(sessionID).To(Not(Equal("")))
+
+ inspectOut, err := containers.ExecInspect(bt.conn, sessionID)
+ Expect(err).To(BeNil())
+ Expect(inspectOut.ContainerID).To(Equal(cid))
+ Expect(inspectOut.ProcessConfig.Entrypoint).To(Equal("echo"))
+ Expect(len(inspectOut.ProcessConfig.Arguments)).To(Equal(1))
+ Expect(inspectOut.ProcessConfig.Arguments[0]).To(Equal("hello world"))
+ })
+
+ It("Podman exec create with bad command fails", func() {
+ name := "testCtr"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+
+ execConfig := new(handlers.ExecCreateConfig)
+
+ _, err = containers.ExecCreate(bt.conn, name, execConfig)
+ Expect(err).To(Not(BeNil()))
+ })
+
+ It("Podman exec create with invalid container fails", func() {
+ execConfig := new(handlers.ExecCreateConfig)
+ execConfig.Cmd = []string{"echo", "hello world"}
+
+ _, err := containers.ExecCreate(bt.conn, "doesnotexist", execConfig)
+ Expect(err).To(Not(BeNil()))
+ })
+
+ It("Podman exec inspect on invalid session fails", func() {
+ _, err := containers.ExecInspect(bt.conn, "0000000000000000000000000000000000000000000000000000000000000000")
+ Expect(err).To(Not(BeNil()))
+ })
+})
diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go
index 5e4cfe7be..992720196 100644
--- a/pkg/bindings/test/images_test.go
+++ b/pkg/bindings/test/images_test.go
@@ -9,6 +9,7 @@ import (
"github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/bindings/images"
+ "github.com/containers/libpod/pkg/domain/entities"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
@@ -16,22 +17,22 @@ import (
var _ = Describe("Podman images", func() {
var (
- //tempdir string
- //err error
- //podmanTest *PodmanTestIntegration
+ // tempdir string
+ // err error
+ // podmanTest *PodmanTestIntegration
bt *bindingTest
s *gexec.Session
err error
)
BeforeEach(func() {
- //tempdir, err = CreateTempDirInTempDir()
- //if err != nil {
+ // tempdir, err = CreateTempDirInTempDir()
+ // if err != nil {
// os.Exit(1)
- //}
- //podmanTest = PodmanTestCreate(tempdir)
- //podmanTest.Setup()
- //podmanTest.SeedImages()
+ // }
+ // podmanTest = PodmanTestCreate(tempdir)
+ // podmanTest.Setup()
+ // podmanTest.SeedImages()
bt = newBindingTest()
bt.RestoreImagesFromCache()
s = bt.startAPIService()
@@ -41,12 +42,13 @@ var _ = Describe("Podman images", func() {
})
AfterEach(func() {
- //podmanTest.Cleanup()
- //f := CurrentGinkgoTestDescription()
- //processTestResult(f)
+ // podmanTest.Cleanup()
+ // f := CurrentGinkgoTestDescription()
+ // processTestResult(f)
s.Kill()
bt.cleanup()
})
+
It("inspect image", func() {
// Inspect invalid image be 404
_, err = images.GetImage(bt.conn, "foobar5000", nil)
@@ -71,7 +73,7 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil())
// TODO it looks like the images API alwaays returns size regardless
// of bool or not. What should we do ?
- //Expect(data.Size).To(BeZero())
+ // Expect(data.Size).To(BeZero())
// Enabling the size parameter should result in size being populated
data, err = images.GetImage(bt.conn, alpine.name, &bindings.PTrue)
@@ -142,7 +144,7 @@ var _ = Describe("Podman images", func() {
err = images.Tag(bt.conn, alpine.shortName, "demo", alpine.shortName)
Expect(err).To(BeNil())
- //Validates if name updates when the image is retagged.
+ // Validates if name updates when the image is retagged.
_, err := images.GetImage(bt.conn, "alpine:demo", nil)
Expect(err).To(BeNil())
@@ -165,7 +167,7 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil())
Expect(len(imageSummary)).To(Equal(3))
- //Validate the image names.
+ // Validate the image names.
var names []string
for _, i := range imageSummary {
names = append(names, i.RepoTags...)
@@ -217,7 +219,7 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil())
names, err := images.Load(bt.conn, f, nil)
Expect(err).To(BeNil())
- Expect(names).To(Equal(alpine.name))
+ Expect(names.Name).To(Equal(alpine.name))
exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
Expect(exists).To(BeTrue())
@@ -233,7 +235,7 @@ var _ = Describe("Podman images", func() {
newName := "quay.io/newname:fizzle"
names, err = images.Load(bt.conn, f, &newName)
Expect(err).To(BeNil())
- Expect(names).To(Equal(alpine.name))
+ Expect(names.Name).To(Equal(alpine.name))
exists, err = images.Exists(bt.conn, newName)
Expect(err).To(BeNil())
Expect(exists).To(BeTrue())
@@ -289,6 +291,7 @@ var _ = Describe("Podman images", func() {
Expect(data.Comment).To(Equal(testMessage))
})
+
It("History Image", func() {
// a bogus name should return a 404
_, err := images.History(bt.conn, "foobar")
@@ -343,4 +346,32 @@ var _ = Describe("Podman images", func() {
Expect(len(imgs)).To(BeNumerically(">=", 1))
})
+ It("Prune images", func() {
+ trueBoxed := true
+ results, err := images.Prune(bt.conn, &trueBoxed, nil)
+ Expect(err).NotTo(HaveOccurred())
+ Expect(len(results)).To(BeNumerically(">", 0))
+ Expect(results).To(ContainElement("docker.io/library/alpine:latest"))
+ })
+
+ // TODO: we really need to extent to pull tests once we have a more sophisticated CI.
+ It("Image Pull", func() {
+ rawImage := "docker.io/library/busybox:latest"
+
+ pulledImages, err := images.Pull(bt.conn, rawImage, entities.ImagePullOptions{})
+ Expect(err).To(BeNil())
+ Expect(len(pulledImages)).To(Equal(1))
+
+ exists, err := images.Exists(bt.conn, rawImage)
+ Expect(err).To(BeNil())
+ Expect(exists).To(BeTrue())
+
+ // Make sure the normalization AND the full-transport reference works.
+ _, err = images.Pull(bt.conn, "docker://"+rawImage, entities.ImagePullOptions{})
+ Expect(err).To(BeNil())
+
+ // The v2 endpoint only supports the docker transport. Let's see if that's really true.
+ _, err = images.Pull(bt.conn, "bogus-transport:bogus.com/image:reference", entities.ImagePullOptions{})
+ Expect(err).To(Not(BeNil()))
+ })
})
diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go
index e94048a9c..2599ec7ef 100644
--- a/pkg/bindings/test/pods_test.go
+++ b/pkg/bindings/test/pods_test.go
@@ -2,11 +2,13 @@ package test_bindings
import (
"net/http"
+ "strings"
"time"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/pods"
+ "github.com/containers/libpod/pkg/specgen"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
@@ -71,7 +73,7 @@ var _ = Describe("Podman pods", func() {
Expect(len(podSummary)).To(Equal(2))
var names []string
for _, i := range podSummary {
- names = append(names, i.Config.Name)
+ names = append(names, i.Name)
}
Expect(StringInSlice(newpod, names)).To(BeTrue())
Expect(StringInSlice("newpod2", names)).To(BeTrue())
@@ -79,9 +81,7 @@ var _ = Describe("Podman pods", func() {
// The test validates the list pod endpoint with passing filters as the params.
It("List pods with filters", func() {
- var (
- newpod2 string = "newpod2"
- )
+ newpod2 := "newpod2"
bt.Podcreate(&newpod2)
_, err = bt.RunTopContainer(nil, &bindings.PTrue, &newpod)
Expect(err).To(BeNil())
@@ -109,13 +109,14 @@ var _ = Describe("Podman pods", func() {
Expect(len(filteredPods)).To(BeNumerically("==", 1))
var names []string
for _, i := range filteredPods {
- names = append(names, i.Config.Name)
+ names = append(names, i.Name)
}
Expect(StringInSlice("newpod2", names)).To(BeTrue())
// Validate list pod with id filter
filters = make(map[string][]string)
response, err := pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
id := response.Config.ID
filters["id"] = []string{id}
filteredPods, err = pods.List(bt.conn, filters)
@@ -123,7 +124,7 @@ var _ = Describe("Podman pods", func() {
Expect(len(filteredPods)).To(BeNumerically("==", 1))
names = names[:0]
for _, i := range filteredPods {
- names = append(names, i.Config.Name)
+ names = append(names, i.Name)
}
Expect(StringInSlice("newpod", names)).To(BeTrue())
@@ -134,7 +135,7 @@ var _ = Describe("Podman pods", func() {
Expect(len(filteredPods)).To(BeNumerically("==", 1))
names = names[:0]
for _, i := range filteredPods {
- names = append(names, i.Config.Name)
+ names = append(names, i.Name)
}
Expect(StringInSlice("newpod", names)).To(BeTrue())
})
@@ -157,7 +158,7 @@ var _ = Describe("Podman pods", func() {
// TODO fix this
Skip("Pod behavior is jacked right now.")
// Pause invalid container
- err := pods.Pause(bt.conn, "dummyName")
+ _, err := pods.Pause(bt.conn, "dummyName")
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
@@ -169,9 +170,10 @@ var _ = Describe("Podman pods", func() {
// Binding needs to be modified to inspect the pod state.
// Since we don't have a pod state we inspect the states of the containers within the pod.
// Pause a valid container
- err = pods.Pause(bt.conn, newpod)
+ _, err = pods.Pause(bt.conn, newpod)
Expect(err).To(BeNil())
response, err := pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStatePaused))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
@@ -179,9 +181,10 @@ var _ = Describe("Podman pods", func() {
}
// Unpause a valid container
- err = pods.Unpause(bt.conn, newpod)
+ _, err = pods.Unpause(bt.conn, newpod)
Expect(err).To(BeNil())
response, err = pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStateRunning))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
@@ -191,28 +194,29 @@ var _ = Describe("Podman pods", func() {
It("start stop restart pod", func() {
// Start an invalid pod
- err = pods.Start(bt.conn, "dummyName")
+ _, err = pods.Start(bt.conn, "dummyName")
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Stop an invalid pod
- err = pods.Stop(bt.conn, "dummyName", nil)
+ _, err = pods.Stop(bt.conn, "dummyName", nil)
Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Restart an invalid pod
- err = pods.Restart(bt.conn, "dummyName")
+ _, err = pods.Restart(bt.conn, "dummyName")
Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Start a valid pod and inspect status of each container
- err = pods.Start(bt.conn, newpod)
+ _, err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil())
response, err := pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStateRunning))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
@@ -220,11 +224,11 @@ var _ = Describe("Podman pods", func() {
}
// Start an already running pod
- err = pods.Start(bt.conn, newpod)
+ _, err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil())
// Stop the running pods
- err = pods.Stop(bt.conn, newpod, nil)
+ _, err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil())
response, _ = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateExited))
@@ -234,10 +238,10 @@ var _ = Describe("Podman pods", func() {
}
// Stop an already stopped pod
- err = pods.Stop(bt.conn, newpod, nil)
+ _, err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil())
- err = pods.Restart(bt.conn, newpod)
+ _, err = pods.Restart(bt.conn, newpod)
Expect(err).To(BeNil())
response, _ = pods.Inspect(bt.conn, newpod)
Expect(response.State.Status).To(Equal(define.PodStateRunning))
@@ -262,11 +266,12 @@ var _ = Describe("Podman pods", func() {
// Prune only one pod which is in exited state.
// Start then stop a pod.
// pod moves to exited state one pod should be pruned now.
- err = pods.Start(bt.conn, newpod)
+ _, err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil())
- err = pods.Stop(bt.conn, newpod, nil)
+ _, err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil())
response, err := pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStateExited))
err = pods.Prune(bt.conn)
Expect(err).To(BeNil())
@@ -276,21 +281,23 @@ var _ = Describe("Podman pods", func() {
// Test prune all pods in exited state.
bt.Podcreate(&newpod)
- err = pods.Start(bt.conn, newpod)
+ _, err = pods.Start(bt.conn, newpod)
Expect(err).To(BeNil())
- err = pods.Start(bt.conn, newpod2)
+ _, err = pods.Start(bt.conn, newpod2)
Expect(err).To(BeNil())
- err = pods.Stop(bt.conn, newpod, nil)
+ _, err = pods.Stop(bt.conn, newpod, nil)
Expect(err).To(BeNil())
response, err = pods.Inspect(bt.conn, newpod)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStateExited))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
To(Equal(define.ContainerStateStopped))
}
- err = pods.Stop(bt.conn, newpod2, nil)
+ _, err = pods.Stop(bt.conn, newpod2, nil)
Expect(err).To(BeNil())
response, err = pods.Inspect(bt.conn, newpod2)
+ Expect(err).To(BeNil())
Expect(response.State.Status).To(Equal(define.PodStateExited))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
@@ -302,4 +309,44 @@ var _ = Describe("Podman pods", func() {
Expect(err).To(BeNil())
Expect(len(podSummary)).To(Equal(0))
})
+
+ It("simple create pod", func() {
+ ps := specgen.PodSpecGenerator{}
+ ps.Name = "foobar"
+ _, err := pods.CreatePodFromSpec(bt.conn, &ps)
+ Expect(err).To(BeNil())
+
+ exists, err := pods.Exists(bt.conn, "foobar")
+ Expect(err).To(BeNil())
+ Expect(exists).To(BeTrue())
+ })
+
+ // Test validates the pod top bindings
+ It("pod top", func() {
+ var name string = "podA"
+
+ bt.Podcreate(&name)
+ _, err := pods.Start(bt.conn, name)
+ Expect(err).To(BeNil())
+
+ // By name
+ _, err = pods.Top(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+
+ // With descriptors
+ output, err := pods.Top(bt.conn, name, []string{"user,pid,hpid"})
+ Expect(err).To(BeNil())
+ header := strings.Split(output[0], "\t")
+ for _, d := range []string{"USER", "PID", "HPID"} {
+ Expect(d).To(BeElementOf(header))
+ }
+
+ // With bogus ID
+ _, err = pods.Top(bt.conn, "IdoNotExist", nil)
+ Expect(err).ToNot(BeNil())
+
+ // With bogus descriptors
+ _, err = pods.Top(bt.conn, name, []string{"Me,Neither"})
+ Expect(err).ToNot(BeNil())
+ })
})