diff options
Diffstat (limited to 'libpod/common_test.go')
-rw-r--r-- | libpod/common_test.go | 46 |
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 { |