summaryrefslogtreecommitdiff
path: root/libpod/common_test.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-09-23 14:02:36 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-01-04 09:51:09 -0500
commit625c7e18ef2b7f47a853c42f1a07fec730dbc91e (patch)
treea6d2c4ffefb916b26cadcd541f1dac5a2863c41c /libpod/common_test.go
parent35361595f36728958e6abb2c37c22d79a776913a (diff)
downloadpodman-625c7e18ef2b7f47a853c42f1a07fec730dbc91e.tar.gz
podman-625c7e18ef2b7f47a853c42f1a07fec730dbc91e.tar.bz2
podman-625c7e18ef2b7f47a853c42f1a07fec730dbc91e.zip
Update unit tests to use in-memory lock manager
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/common_test.go')
-rw-r--r--libpod/common_test.go46
1 files changed, 25 insertions, 21 deletions
diff --git a/libpod/common_test.go b/libpod/common_test.go
index 6c7434fd2..882468a3a 100644
--- a/libpod/common_test.go
+++ b/libpod/common_test.go
@@ -3,20 +3,19 @@ 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{
ID: id,
@@ -90,18 +89,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 +114,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
@@ -174,6 +174,8 @@ func testContainersEqual(t *testing.T, a, b *Container, allowedEmpty bool) {
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 +225,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 {