summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/system/system.go38
-rw-r--r--pkg/bindings/test/containers_test.go141
2 files changed, 179 insertions, 0 deletions
diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go
index df6b529de..caef6af6f 100644
--- a/pkg/bindings/system/system.go
+++ b/pkg/bindings/system/system.go
@@ -3,11 +3,14 @@ package system
import (
"context"
"encoding/json"
+ "fmt"
"io"
"net/http"
"net/url"
"strconv"
+ "time"
+ "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/pkg/errors"
@@ -83,3 +86,38 @@ func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport
}
return &report, response.Process(&report)
}
+
+func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
+ var report entities.SystemVersionReport
+ var component entities.ComponentVersion
+
+ version, err := define.GetVersion()
+ if err != nil {
+ return nil, err
+ }
+ report.Client = &version
+
+ conn, err := bindings.GetClient(ctx)
+ if err != nil {
+ return nil, err
+ }
+ response, err := conn.DoRequest(nil, http.MethodGet, "/version", nil)
+ if err != nil {
+ return nil, err
+ }
+
+ if err = response.Process(&component); err != nil {
+ return nil, err
+ }
+ f, _ := strconv.ParseFloat(component.APIVersion, 64)
+ b, _ := time.Parse(time.RFC3339, component.BuildTime)
+ report.Server = &define.Version{
+ RemoteAPIVersion: int64(f),
+ Version: component.Version.Version,
+ GoVersion: component.GoVersion,
+ GitCommit: component.GitCommit,
+ Built: b.Unix(),
+ OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
+ }
+ return &report, err
+}
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index f40d8ce46..328691df2 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -596,4 +596,145 @@ var _ = Describe("Podman containers ", func() {
Expect(err).To(BeNil())
Expect(len(pruneResponse.ID)).To(Equal(0))
})
+
+ It("podman inspect bogus container", func() {
+ _, err := containers.Inspect(bt.conn, "foobar", nil)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusNotFound))
+ })
+
+ It("podman inspect running container", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Inspecting running container should succeed
+ _, err = containers.Inspect(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+ })
+
+ It("podman inspect stopped container", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ err = containers.Stop(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+ // Inspecting stopped container should succeed
+ _, err = containers.Inspect(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+ })
+
+ It("podman inspect running container with size", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ _, err = containers.Inspect(bt.conn, name, &bindings.PTrue)
+ Expect(err).To(BeNil())
+ })
+
+ It("podman inspect stopped container with size", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ err = containers.Stop(bt.conn, name, nil)
+ Expect(err).To(BeNil())
+ // Inspecting stopped container with size should succeed
+ _, err = containers.Inspect(bt.conn, name, &bindings.PTrue)
+ Expect(err).To(BeNil())
+ })
+
+ It("podman remove bogus container", func() {
+ err = containers.Remove(bt.conn, "foobar", nil, nil)
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusNotFound))
+ })
+
+ It("podman remove running container by name", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, name, nil, nil)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman remove running container by ID", func() {
+ var name = "top"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, cid, nil, nil)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman forcibly remove running container by name", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, name, &bindings.PTrue, nil)
+ Expect(err).To(BeNil())
+ //code, _ := bindings.CheckResponseCode(err)
+ //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman forcibly remove running container by ID", func() {
+ var name = "top"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, cid, &bindings.PTrue, nil)
+ Expect(err).To(BeNil())
+ //code, _ := bindings.CheckResponseCode(err)
+ //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman remove running container and volume by name", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, name, nil, &bindings.PTrue)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman remove running container and volume by ID", func() {
+ var name = "top"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, cid, nil, &bindings.PTrue)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman forcibly remove running container and volume by name", func() {
+ var name = "top"
+ _, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, name, &bindings.PTrue, &bindings.PTrue)
+ Expect(err).To(BeNil())
+ //code, _ := bindings.CheckResponseCode(err)
+ //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
+ It("podman forcibly remove running container and volume by ID", func() {
+ var name = "top"
+ cid, err := bt.RunTopContainer(&name, &bindings.PFalse, nil)
+ Expect(err).To(BeNil())
+ // Removing running container should fail
+ err = containers.Remove(bt.conn, cid, &bindings.PTrue, &bindings.PTrue)
+ Expect(err).To(BeNil())
+ //code, _ := bindings.CheckResponseCode(err)
+ //Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
+ })
+
})