diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-09-23 14:02:36 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-01-04 09:51:09 -0500 |
commit | 625c7e18ef2b7f47a853c42f1a07fec730dbc91e (patch) | |
tree | a6d2c4ffefb916b26cadcd541f1dac5a2863c41c /libpod/container_graph_test.go | |
parent | 35361595f36728958e6abb2c37c22d79a776913a (diff) | |
download | podman-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/container_graph_test.go')
-rw-r--r-- | libpod/container_graph_test.go | 160 |
1 files changed, 87 insertions, 73 deletions
diff --git a/libpod/container_graph_test.go b/libpod/container_graph_test.go index 25461f1f4..d1a52658d 100644 --- a/libpod/container_graph_test.go +++ b/libpod/container_graph_test.go @@ -1,10 +1,9 @@ package libpod import ( - "io/ioutil" - "os" "testing" + "github.com/containers/libpod/libpod/lock" "github.com/stretchr/testify/assert" ) @@ -17,11 +16,12 @@ func TestBuildContainerGraphNoCtrsIsEmpty(t *testing.T) { } func TestBuildContainerGraphOneCtr(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) graph, err := buildContainerGraph([]*Container{ctr1}) @@ -39,13 +39,14 @@ func TestBuildContainerGraphOneCtr(t *testing.T) { } func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) graph, err := buildContainerGraph([]*Container{ctr1, ctr2}) @@ -64,13 +65,14 @@ func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) { } func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) ctr2.config.UserNsCtr = ctr1.config.ID @@ -85,13 +87,14 @@ func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) { } func TestBuildContainerGraphTwoCtrCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) ctr2.config.UserNsCtr = ctr1.config.ID ctr1.config.NetNsCtr = ctr2.config.ID @@ -101,15 +104,16 @@ func TestBuildContainerGraphTwoCtrCycle(t *testing.T) { } func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3}) @@ -132,15 +136,16 @@ func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) { } func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) ctr1.config.UserNsCtr = ctr2.config.ID ctr2.config.IPCNsCtr = ctr1.config.ID @@ -150,15 +155,16 @@ func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) { } func TestBuildContainerGraphThreeContainersCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) ctr1.config.UserNsCtr = ctr2.config.ID ctr2.config.IPCNsCtr = ctr3.config.ID @@ -169,15 +175,16 @@ func TestBuildContainerGraphThreeContainersCycle(t *testing.T) { } func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) ctr1.config.UserNsCtr = ctr2.config.ID ctr1.config.NetNsCtr = ctr3.config.ID @@ -194,17 +201,18 @@ func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) { } func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) - ctr4, err := getTestCtrN("4", tmpDir) + ctr4, err := getTestCtrN("4", manager) assert.NoError(t, err) graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3, ctr4}) @@ -231,18 +239,20 @@ func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) { } func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) - ctr4, err := getTestCtrN("4", tmpDir) + ctr4, err := getTestCtrN("4", manager) assert.NoError(t, err) + ctr1.config.IPCNsCtr = ctr2.config.ID ctr2.config.UserNsCtr = ctr1.config.ID @@ -251,18 +261,20 @@ func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) { } func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) - ctr4, err := getTestCtrN("4", tmpDir) + ctr4, err := getTestCtrN("4", manager) assert.NoError(t, err) + ctr1.config.IPCNsCtr = ctr2.config.ID ctr2.config.UserNsCtr = ctr3.config.ID ctr3.config.NetNsCtr = ctr4.config.ID @@ -273,18 +285,20 @@ func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) { } func TestBuildContainerGraphFourContainersNoneInCycle(t *testing.T) { - tmpDir, err := ioutil.TempDir("", tmpDirPrefix) - assert.NoError(t, err) - defer os.RemoveAll(tmpDir) + manager, err := lock.NewInMemoryManager(16) + if err != nil { + t.Fatalf("Error setting up locks: %v", err) + } - ctr1, err := getTestCtr1(tmpDir) + ctr1, err := getTestCtr1(manager) assert.NoError(t, err) - ctr2, err := getTestCtr2(tmpDir) + ctr2, err := getTestCtr2(manager) assert.NoError(t, err) - ctr3, err := getTestCtrN("3", tmpDir) + ctr3, err := getTestCtrN("3", manager) assert.NoError(t, err) - ctr4, err := getTestCtrN("4", tmpDir) + ctr4, err := getTestCtrN("4", manager) assert.NoError(t, err) + ctr1.config.IPCNsCtr = ctr2.config.ID ctr1.config.NetNsCtr = ctr3.config.ID ctr2.config.UserNsCtr = ctr3.config.ID |