summaryrefslogtreecommitdiff
path: root/libpod/state_test.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-31 19:58:31 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-03 14:57:16 +0000
commita1c0f18bcac9e0b21b4abbb4e49bea4336842e4e (patch)
treec54147b99c04f02b528857840310f43213c7608b /libpod/state_test.go
parent838df4eec4496868e772d5708e00f38bad478718 (diff)
downloadpodman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.tar.gz
podman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.tar.bz2
podman-a1c0f18bcac9e0b21b4abbb4e49bea4336842e4e.zip
Add backend code for generic dependencies
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #577 Approved by: rhatdan
Diffstat (limited to 'libpod/state_test.go')
-rw-r--r--libpod/state_test.go117
1 files changed, 117 insertions, 0 deletions
diff --git a/libpod/state_test.go b/libpod/state_test.go
index f989dfefd..f0c65b134 100644
--- a/libpod/state_test.go
+++ b/libpod/state_test.go
@@ -656,6 +656,83 @@ func TestContainerInUseOneContainerMultipleDependencies(t *testing.T) {
})
}
+func TestContainerInUseGenericDependency(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testCtr1, err := getTestCtr1(lockPath)
+ assert.NoError(t, err)
+ testCtr2, err := getTestCtr2(lockPath)
+ assert.NoError(t, err)
+
+ testCtr2.config.Dependencies = []string{testCtr1.config.ID}
+
+ err = state.AddContainer(testCtr1)
+ assert.NoError(t, err)
+
+ err = state.AddContainer(testCtr2)
+ assert.NoError(t, err)
+
+ ids, err := state.ContainerInUse(testCtr1)
+ assert.NoError(t, err)
+ assert.Equal(t, 1, len(ids))
+ assert.Equal(t, testCtr2.config.ID, ids[0])
+ })
+}
+
+func TestContainerInUseMultipleGenericDependencies(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testCtr1, err := getTestCtr1(lockPath)
+ assert.NoError(t, err)
+ testCtr2, err := getTestCtr2(lockPath)
+ assert.NoError(t, err)
+ testCtr3, err := getTestCtrN("3", lockPath)
+ assert.NoError(t, err)
+
+ testCtr3.config.Dependencies = []string{testCtr1.config.ID, testCtr2.config.ID}
+
+ err = state.AddContainer(testCtr1)
+ assert.NoError(t, err)
+
+ err = state.AddContainer(testCtr2)
+ assert.NoError(t, err)
+
+ err = state.AddContainer(testCtr3)
+ assert.NoError(t, err)
+
+ ids1, err := state.ContainerInUse(testCtr1)
+ assert.NoError(t, err)
+ assert.Equal(t, 1, len(ids1))
+ assert.Equal(t, testCtr3.config.ID, ids1[0])
+
+ ids2, err := state.ContainerInUse(testCtr2)
+ assert.NoError(t, err)
+ assert.Equal(t, 1, len(ids2))
+ assert.Equal(t, testCtr3.config.ID, ids2[0])
+ })
+}
+
+func TestContainerInUseGenericAndNamespaceDependencies(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testCtr1, err := getTestCtr1(lockPath)
+ assert.NoError(t, err)
+ testCtr2, err := getTestCtr2(lockPath)
+ assert.NoError(t, err)
+
+ testCtr2.config.Dependencies = []string{testCtr1.config.ID}
+ testCtr2.config.IPCNsCtr = testCtr1.config.ID
+
+ err = state.AddContainer(testCtr1)
+ assert.NoError(t, err)
+
+ err = state.AddContainer(testCtr2)
+ assert.NoError(t, err)
+
+ ids, err := state.ContainerInUse(testCtr1)
+ assert.NoError(t, err)
+ assert.Equal(t, 1, len(ids))
+ assert.Equal(t, testCtr2.config.ID, ids[0])
+ })
+}
+
func TestCannotRemoveContainerWithDependency(t *testing.T) {
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
testCtr1, err := getTestCtr1(lockPath)
@@ -680,6 +757,30 @@ func TestCannotRemoveContainerWithDependency(t *testing.T) {
})
}
+func TestCannotRemoveContainerWithGenericDependency(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testCtr1, err := getTestCtr1(lockPath)
+ assert.NoError(t, err)
+ testCtr2, err := getTestCtr2(lockPath)
+ assert.NoError(t, err)
+
+ testCtr2.config.Dependencies = []string{testCtr1.config.ID}
+
+ err = state.AddContainer(testCtr1)
+ assert.NoError(t, err)
+
+ err = state.AddContainer(testCtr2)
+ assert.NoError(t, err)
+
+ err = state.RemoveContainer(testCtr1)
+ assert.Error(t, err)
+
+ ctrs, err := state.AllContainers()
+ assert.NoError(t, err)
+ assert.Equal(t, 2, len(ctrs))
+ })
+}
+
func TestCanRemoveContainerAfterDependencyRemoved(t *testing.T) {
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
testCtr1, err := getTestCtr1(lockPath)
@@ -773,6 +874,22 @@ func TestCannotUseBadIDAsDependency(t *testing.T) {
})
}
+func TestCannotUseBadIDAsGenericDependency(t *testing.T) {
+ runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ testCtr, err := getTestCtr1(lockPath)
+ assert.NoError(t, err)
+
+ testCtr.config.Dependencies = []string{strings.Repeat("5", 32)}
+
+ err = state.AddContainer(testCtr)
+ assert.Error(t, err)
+
+ ctrs, err := state.AllContainers()
+ assert.NoError(t, err)
+ assert.Equal(t, 0, len(ctrs))
+ })
+}
+
func TestGetPodDoesNotExist(t *testing.T) {
runForAllStates(t, func(t *testing.T, state State, lockPath string) {
_, err := state.Pod("doesnotexist")