From 4ecebf20b4e41720b9a0b55e0c22f05061c77e60 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 29 Jan 2018 04:59:25 -0500 Subject: Rework state tests to avoid boilerplate. Begin adding pod tests. Signed-off-by: Matthew Heon Closes: #268 Approved by: rhatdan --- libpod/test_common.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'libpod/test_common.go') 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) +} -- cgit v1.2.3-54-g00ecf