summaryrefslogtreecommitdiff
path: root/libpod/common_test.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-07-30 13:54:22 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-07-31 14:19:50 +0000
commitc7c56d800c21147252d388d09954d0c2e8faf9da (patch)
tree2d3ad0e20687113469bc08815ed024e294c2c9a9 /libpod/common_test.go
parentf4120f9662ec94f4972854e78b742dd96297d1eb (diff)
downloadpodman-c7c56d800c21147252d388d09954d0c2e8faf9da.tar.gz
podman-c7c56d800c21147252d388d09954d0c2e8faf9da.tar.bz2
podman-c7c56d800c21147252d388d09954d0c2e8faf9da.zip
Rework state testing to allow State structs to be empty
Pod and container State structs are now allowed to be empty on first being retrieved from the database. Rework pod and container equality functions used in testing to account for this change. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #1186 Approved by: rhatdan
Diffstat (limited to 'libpod/common_test.go')
-rw-r--r--libpod/common_test.go48
1 files changed, 33 insertions, 15 deletions
diff --git a/libpod/common_test.go b/libpod/common_test.go
index 543242130..b7fee2764 100644
--- a/libpod/common_test.go
+++ b/libpod/common_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"net"
"path/filepath"
+ "reflect"
"strings"
"testing"
"time"
@@ -145,23 +146,27 @@ func getTestPod2(lockPath string) (*Pod, error) {
// 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
-func testContainersEqual(t *testing.T, a, b *Container) {
+// For some operations (container retrieval from the database) state is allowed
+// to be empty. This is controlled by the allowedEmpty bool.
+func testContainersEqual(t *testing.T, a, b *Container, allowedEmpty bool) {
if a == nil && b == nil {
return
}
require.NotNil(t, a)
require.NotNil(t, b)
- assert.NotNil(t, a.config)
- assert.NotNil(t, b.config)
- assert.NotNil(t, a.state)
- assert.NotNil(t, b.state)
+ require.NotNil(t, a.config)
+ require.NotNil(t, b.config)
+ require.NotNil(t, a.state)
+ require.NotNil(t, b.state)
aConfig := new(ContainerConfig)
bConfig := new(ContainerConfig)
aState := new(containerState)
bState := new(containerState)
+ blankState := new(containerState)
+
assert.Equal(t, a.valid, b.valid)
aConfigJSON, err := json.Marshal(a.config)
@@ -186,25 +191,38 @@ func testContainersEqual(t *testing.T, a, b *Container) {
err = json.Unmarshal(bStateJSON, bState)
assert.NoError(t, err)
- assert.EqualValues(t, aState, bState)
+ if allowedEmpty {
+ assert.True(t, reflect.DeepEqual(aState, bState) || reflect.DeepEqual(aState, blankState))
+ } else {
+ assert.EqualValues(t, aState, bState)
+ }
}
-// Test if pods are equal
-func testPodsEqual(t *testing.T, a, b *Pod) {
+// Test if pods are equal.
+// For some operations (pod retrieval from the database) state is allowed to be
+// empty. This is controlled by the allowedEmpty bool.
+func testPodsEqual(t *testing.T, a, b *Pod, allowedEmpty bool) {
if a == nil && b == nil {
return
}
- assert.NotNil(t, a)
- assert.NotNil(t, b)
+ blankState := new(podState)
- assert.NotNil(t, a.config)
- assert.NotNil(t, b.config)
- assert.NotNil(t, a.state)
- assert.NotNil(t, b.state)
+ require.NotNil(t, a)
+ require.NotNil(t, b)
+
+ require.NotNil(t, a.config)
+ require.NotNil(t, b.config)
+ require.NotNil(t, a.state)
+ require.NotNil(t, b.state)
assert.Equal(t, a.valid, b.valid)
assert.EqualValues(t, a.config, b.config)
- assert.EqualValues(t, a.state, b.state)
+
+ if allowedEmpty {
+ assert.True(t, reflect.DeepEqual(a.state, b.state) || reflect.DeepEqual(a.state, blankState))
+ } else {
+ assert.EqualValues(t, a.state, b.state)
+ }
}