aboutsummaryrefslogtreecommitdiff
path: root/libpod/state_test.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-05-14 19:30:11 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-17 23:10:12 +0000
commit018d2c6b1d23acf7fe67e809498bc354eaf6becf (patch)
tree7e4a605898905c0e0b259717d642ecbabf2516d3 /libpod/state_test.go
parentc45d4c6d5ce83a89f4c536e529c2a6e7a770837e (diff)
downloadpodman-018d2c6b1d23acf7fe67e809498bc354eaf6becf.tar.gz
podman-018d2c6b1d23acf7fe67e809498bc354eaf6becf.tar.bz2
podman-018d2c6b1d23acf7fe67e809498bc354eaf6becf.zip
Add pod state
Add a mutable state to pods, and database backend sutable for modifying and updating said state. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #784 Approved by: rhatdan
Diffstat (limited to 'libpod/state_test.go')
-rw-r--r--libpod/state_test.go82
1 files changed, 67 insertions, 15 deletions
diff --git a/libpod/state_test.go b/libpod/state_test.go
index f0c65b134..4d5eb9713 100644
--- a/libpod/state_test.go
+++ b/libpod/state_test.go
@@ -915,8 +915,7 @@ func TestGetPodOnePod(t *testing.T) {
statePod, err := state.Pod(testPod.ID())
assert.NoError(t, err)
- assert.EqualValues(t, testPod.config, statePod.config)
- assert.Equal(t, testPod.valid, statePod.valid)
+ testPodsEqual(t, testPod, statePod)
})
}
@@ -937,8 +936,7 @@ func TestGetOnePodFromTwo(t *testing.T) {
statePod, err := state.Pod(testPod1.ID())
assert.NoError(t, err)
- assert.EqualValues(t, testPod1.config, statePod.config)
- assert.Equal(t, testPod1.valid, statePod.valid)
+ testPodsEqual(t, testPod1, statePod)
})
}
@@ -999,8 +997,7 @@ func TestLookupPodFullID(t *testing.T) {
statePod, err := state.LookupPod(testPod.ID())
assert.NoError(t, err)
- assert.EqualValues(t, testPod.config, statePod.config)
- assert.Equal(t, testPod.valid, statePod.valid)
+ testPodsEqual(t, testPod, statePod)
})
}
@@ -1015,8 +1012,7 @@ func TestLookupPodUniquePartialID(t *testing.T) {
statePod, err := state.LookupPod(testPod.ID()[0:8])
assert.NoError(t, err)
- assert.EqualValues(t, testPod.config, statePod.config)
- assert.Equal(t, testPod.valid, statePod.valid)
+ testPodsEqual(t, testPod, statePod)
})
}
@@ -1050,8 +1046,7 @@ func TestLookupPodByName(t *testing.T) {
statePod, err := state.LookupPod(testPod.Name())
assert.NoError(t, err)
- assert.EqualValues(t, testPod.config, statePod.config)
- assert.Equal(t, testPod.valid, statePod.valid)
+ testPodsEqual(t, testPod, statePod)
})
}
@@ -1157,7 +1152,7 @@ func TestAddPodValidPodSucceeds(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(allPods))
- assert.EqualValues(t, testPod.config, allPods[0].config)
+ testPodsEqual(t, testPod, allPods[0])
assert.Equal(t, testPod.valid, allPods[0].valid)
})
}
@@ -1318,8 +1313,7 @@ func TestRemovePodFromPods(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(allPods))
- assert.EqualValues(t, testPod2.config, allPods[0].config)
- assert.Equal(t, testPod2.valid, allPods[0].valid)
+ testPodsEqual(t, testPod2, allPods[0])
})
}
@@ -1394,8 +1388,7 @@ func TestAllPodsFindsPod(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(allPods))
- assert.EqualValues(t, testPod.config, allPods[0].config)
- assert.Equal(t, testPod.valid, allPods[0].valid)
+ testPodsEqual(t, testPod, allPods[0])
})
}
@@ -2403,3 +2396,62 @@ func TestRemoveContainerFromPodWithDependencySucceedsAfterDepRemoved(t *testing.
assert.Equal(t, 0, len(allCtrs))
})
}
+
+func TestUpdatePodInvalidPod(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ err := state.UpdatePod(&Pod{config: &PodConfig{}})
+ assert.Error(t, err)
+ })
+}
+
+func TestUpdatePodPodNotInStateFails(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testPod, err := getTestPod1(lockPath)
+ assert.NoError(t, err)
+
+ err = state.UpdatePod(testPod)
+ assert.Error(t, err)
+ })
+}
+
+func TestSavePodInvalidPod(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ err := state.SavePod(&Pod{config: &PodConfig{}})
+ assert.Error(t, err)
+ })
+}
+
+func TestSavePodPodNotInStateFails(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testPod, err := getTestPod1(lockPath)
+ assert.NoError(t, err)
+
+ err = state.SavePod(testPod)
+ assert.Error(t, err)
+ })
+}
+
+func TestSaveAndUpdatePod(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testPod, err := getTestPod1(lockPath)
+ assert.NoError(t, err)
+
+ err = state.AddPod(testPod)
+ assert.NoError(t, err)
+
+ statePod, err := state.Pod(testPod.ID())
+ assert.NoError(t, err)
+
+ testPodsEqual(t, testPod, statePod)
+
+ testPod.state.CgroupPath = "/new/path/for/test"
+
+ err = state.SavePod(testPod)
+ assert.NoError(t, err)
+
+ err = state.UpdatePod(statePod)
+ assert.NoError(t, err)
+
+ testPodsEqual(t, testPod, statePod)
+ })
+}