summaryrefslogtreecommitdiff
path: root/libpod/test_common.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-01-29 04:59:25 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-09 15:01:34 +0000
commit4ecebf20b4e41720b9a0b55e0c22f05061c77e60 (patch)
treec1864f919fe7f4290b190ac2f330d97e466af58b /libpod/test_common.go
parent0920e8de5a08328cceb70617ee04ef177b30d355 (diff)
downloadpodman-4ecebf20b4e41720b9a0b55e0c22f05061c77e60.tar.gz
podman-4ecebf20b4e41720b9a0b55e0c22f05061c77e60.tar.bz2
podman-4ecebf20b4e41720b9a0b55e0c22f05061c77e60.zip
Rework state tests to avoid boilerplate. Begin adding pod tests.
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #268 Approved by: rhatdan
Diffstat (limited to 'libpod/test_common.go')
-rw-r--r--libpod/test_common.go44
1 files changed, 43 insertions, 1 deletions
diff --git a/libpod/test_common.go b/libpod/test_common.go
index b6188ce80..ad3020b7e 100644
--- a/libpod/test_common.go
+++ b/libpod/test_common.go
@@ -24,7 +24,7 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
StaticDir: "/does/not/exist/",
LogPath: "/does/not/exist/",
Stdin: true,
- Labels: make(map[string]string),
+ Labels: map[string]string{"a": "b", "c": "d"},
StopSignal: 0,
StopTimeout: 0,
CreatedTime: time.Now(),
@@ -74,6 +74,25 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
return ctr, nil
}
+// nolint
+func getTestPod(id, name, locksDir string) (*Pod, error) {
+ pod := &Pod{
+ id: id,
+ name: name,
+ labels: map[string]string{"a": "b", "c": "d"},
+ valid: true,
+ }
+
+ lockPath := filepath.Join(locksDir, id)
+ lock, err := storage.GetLockfile(lockPath)
+ if err != nil {
+ return nil, err
+ }
+ pod.lock = lock
+
+ return pod, nil
+}
+
// This horrible hack tests if containers are equal in a way that should handle
// empty arrays being dropped to nil pointers in the spec JSON
// nolint
@@ -114,3 +133,26 @@ func testContainersEqual(a, b *Container) bool {
return reflect.DeepEqual(aStateJSON, bStateJSON)
}
+
+// This tests pod equality
+// We cannot guarantee equality in lockfile objects so we can't simply compare
+// nolint
+func testPodsEqual(a, b *Pod) bool {
+ if a == nil && b == nil {
+ return true
+ } else if a == nil || b == nil {
+ return false
+ }
+
+ if a.id != b.id {
+ return false
+ }
+ if a.name != b.name {
+ return false
+ }
+ if a.valid != b.valid {
+ return false
+ }
+
+ return reflect.DeepEqual(a.labels, b.labels)
+}