summaryrefslogtreecommitdiff
path: root/libpod/test_common.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-02-12 11:48:20 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-16 16:46:09 +0000
commitf2041b51f39855f288f8feb486c5726587ebe90a (patch)
treee7b059b851c3cf3b46630f2ef778844322d74765 /libpod/test_common.go
parent445aaf87fae22fb38e68f2bc158e833fa58141bc (diff)
downloadpodman-f2041b51f39855f288f8feb486c5726587ebe90a.tar.gz
podman-f2041b51f39855f288f8feb486c5726587ebe90a.tar.bz2
podman-f2041b51f39855f288f8feb486c5726587ebe90a.zip
Add FFJSON encoding/decoding for our container structs
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #323 Approved by: mheon
Diffstat (limited to 'libpod/test_common.go')
-rw-r--r--libpod/test_common.go50
1 files changed, 26 insertions, 24 deletions
diff --git a/libpod/test_common.go b/libpod/test_common.go
index 28053eacb..9e52c74a5 100644
--- a/libpod/test_common.go
+++ b/libpod/test_common.go
@@ -4,12 +4,13 @@ import (
"encoding/json"
"net"
"path/filepath"
- "reflect"
+ "testing"
"time"
"github.com/containers/storage"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/opencontainers/runtime-tools/generate"
+ "github.com/stretchr/testify/assert"
)
// nolint
@@ -98,40 +99,41 @@ func getTestPod(id, name, locksDir 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
// nolint
-func testContainersEqual(a, b *Container) bool {
+func testContainersEqual(t *testing.T, a, b *Container) {
if a == nil && b == nil {
- return true
- } else if a == nil || b == nil {
- return false
+ return
}
+ assert.NotNil(t, a)
+ assert.NotNil(t, b)
- if a.valid != b.valid {
- return false
- }
+ aConfig := new(ContainerConfig)
+ bConfig := new(ContainerConfig)
+ aState := new(containerState)
+ bState := new(containerState)
+
+ assert.Equal(t, a.valid, b.valid)
aConfigJSON, err := json.Marshal(a.config)
- if err != nil {
- return false
- }
+ assert.NoError(t, err)
+ err = json.Unmarshal(aConfigJSON, aConfig)
+ assert.NoError(t, err)
bConfigJSON, err := json.Marshal(b.config)
- if err != nil {
- return false
- }
+ assert.NoError(t, err)
+ err = json.Unmarshal(bConfigJSON, bConfig)
+ assert.NoError(t, err)
- if !reflect.DeepEqual(aConfigJSON, bConfigJSON) {
- return false
- }
+ assert.EqualValues(t, aConfig, bConfig)
aStateJSON, err := json.Marshal(a.state)
- if err != nil {
- return false
- }
+ assert.NoError(t, err)
+ err = json.Unmarshal(aStateJSON, aState)
+ assert.NoError(t, err)
bStateJSON, err := json.Marshal(b.state)
- if err != nil {
- return false
- }
+ assert.NoError(t, err)
+ err = json.Unmarshal(bStateJSON, bState)
+ assert.NoError(t, err)
- return reflect.DeepEqual(aStateJSON, bStateJSON)
+ assert.EqualValues(t, aState, bState)
}