summaryrefslogtreecommitdiff
path: root/libpod/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/common_test.go')
-rw-r--r--libpod/common_test.go61
1 files changed, 32 insertions, 29 deletions
diff --git a/libpod/common_test.go b/libpod/common_test.go
index 6c7434fd2..df730098e 100644
--- a/libpod/common_test.go
+++ b/libpod/common_test.go
@@ -1,24 +1,22 @@
package libpod
import (
- "encoding/json"
"net"
- "path/filepath"
"reflect"
"strings"
"testing"
"time"
- "github.com/containers/storage"
+ "github.com/containers/libpod/libpod/lock"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/opencontainers/runtime-tools/generate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
-func getTestContainer(id, name, locksDir string) (*Container, error) {
+func getTestContainer(id, name string, manager lock.Manager) (*Container, error) {
ctr := &Container{
- config: &Config{
+ config: &ContainerConfig{
ID: id,
Name: name,
RootfsImageID: id,
@@ -50,7 +48,7 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
},
},
},
- state: &containerState{
+ state: &ContainerState{
State: ContainerStateRunning,
ConfigPath: "/does/not/exist/specs/" + id,
RunDir: "/does/not/exist/tmp/",
@@ -90,18 +88,18 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
ctr.config.Labels["test"] = "testing"
- // Must make lockfile or container will error on being retrieved from DB
- lockPath := filepath.Join(locksDir, id)
- lock, err := storage.GetLockfile(lockPath)
+ // Allocate a lock for the container
+ lock, err := manager.AllocateLock()
if err != nil {
return nil, err
}
ctr.lock = lock
+ ctr.config.LockID = lock.ID()
return ctr, nil
}
-func getTestPod(id, name, locksDir string) (*Pod, error) {
+func getTestPod(id, name string, manager lock.Manager) (*Pod, error) {
pod := &Pod{
config: &PodConfig{
ID: id,
@@ -115,38 +113,39 @@ func getTestPod(id, name, locksDir string) (*Pod, error) {
valid: true,
}
- lockPath := filepath.Join(locksDir, id)
- lock, err := storage.GetLockfile(lockPath)
+ // Allocate a lock for the pod
+ lock, err := manager.AllocateLock()
if err != nil {
return nil, err
}
pod.lock = lock
+ pod.config.LockID = lock.ID()
return pod, nil
}
-func getTestCtrN(n, lockPath string) (*Container, error) {
- return getTestContainer(strings.Repeat(n, 32), "test"+n, lockPath)
+func getTestCtrN(n string, manager lock.Manager) (*Container, error) {
+ return getTestContainer(strings.Repeat(n, 32), "test"+n, manager)
}
-func getTestCtr1(lockPath string) (*Container, error) {
- return getTestCtrN("1", lockPath)
+func getTestCtr1(manager lock.Manager) (*Container, error) {
+ return getTestCtrN("1", manager)
}
-func getTestCtr2(lockPath string) (*Container, error) {
- return getTestCtrN("2", lockPath)
+func getTestCtr2(manager lock.Manager) (*Container, error) {
+ return getTestCtrN("2", manager)
}
-func getTestPodN(n, lockPath string) (*Pod, error) {
- return getTestPod(strings.Repeat(n, 32), "test"+n, lockPath)
+func getTestPodN(n string, manager lock.Manager) (*Pod, error) {
+ return getTestPod(strings.Repeat(n, 32), "test"+n, manager)
}
-func getTestPod1(lockPath string) (*Pod, error) {
- return getTestPodN("1", lockPath)
+func getTestPod1(manager lock.Manager) (*Pod, error) {
+ return getTestPodN("1", manager)
}
-func getTestPod2(lockPath string) (*Pod, error) {
- return getTestPodN("2", lockPath)
+func getTestPod2(manager lock.Manager) (*Pod, error) {
+ return getTestPodN("2", manager)
}
// This horrible hack tests if containers are equal in a way that should handle
@@ -165,15 +164,17 @@ func testContainersEqual(t *testing.T, a, b *Container, allowedEmpty bool) {
require.NotNil(t, a.state)
require.NotNil(t, b.state)
- aConfig := new(Config)
- bConfig := new(Config)
- aState := new(containerState)
- bState := new(containerState)
+ aConfig := new(ContainerConfig)
+ bConfig := new(ContainerConfig)
+ aState := new(ContainerState)
+ bState := new(ContainerState)
- blankState := new(containerState)
+ blankState := new(ContainerState)
assert.Equal(t, a.valid, b.valid)
+ assert.Equal(t, a.lock.ID(), b.lock.ID())
+
aConfigJSON, err := json.Marshal(a.config)
assert.NoError(t, err)
err = json.Unmarshal(aConfigJSON, aConfig)
@@ -223,6 +224,8 @@ func testPodsEqual(t *testing.T, a, b *Pod, allowedEmpty bool) {
assert.Equal(t, a.valid, b.valid)
+ assert.Equal(t, a.lock.ID(), b.lock.ID())
+
assert.EqualValues(t, a.config, b.config)
if allowedEmpty {