mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add image removal unit tests
This commit is contained in:
parent
3cd34f1039
commit
c0b9afbf01
2 changed files with 138 additions and 0 deletions
132
fs/remove_test.go
Normal file
132
fs/remove_test.go
Normal file
|
@ -0,0 +1,132 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/fake"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func countImages(store *Store) int {
|
||||
paths, err := store.Images()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return len(paths)
|
||||
}
|
||||
|
||||
func TestRemoveInPath(t *testing.T) {
|
||||
store, err := TempStore("test-remove-in-path")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(store)
|
||||
archive, err := fake.FakeTar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
images := make([]*Image, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
if image, err := store.Create(archive, nil, "foo", "Testing"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
images[i] = image
|
||||
}
|
||||
}
|
||||
if c := countImages(store); c != 10 {
|
||||
t.Fatalf("Expected 10 images, %d found", c)
|
||||
}
|
||||
if err := store.RemoveInPath("foo"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
store, err := TempStore("test-remove")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(store)
|
||||
archive, err := fake.FakeTar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
|
||||
// Test 1 create / 1 delete
|
||||
img, err := store.Create(archive, nil, "foo", "Testing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 1 {
|
||||
t.Fatalf("Expected 1 images, %d found", c)
|
||||
}
|
||||
if err := store.Remove(img); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
|
||||
// Test 2 create (same name) / 1 delete
|
||||
img1, err := store.Create(archive, nil, "foo", "Testing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
img2, err := store.Create(archive, nil, "foo", "Testing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 2 {
|
||||
t.Fatalf("Expected 2 images, %d found", c)
|
||||
}
|
||||
if err := store.Remove(img1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 1 {
|
||||
t.Fatalf("Expected 1 images, %d found", c)
|
||||
}
|
||||
|
||||
// Test delete wrong name
|
||||
// Note: If we change orm and Delete of non existing return error, we will need to change this test
|
||||
if err := store.Remove(&Image{Id: "Not_foo", store: img2.store}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 1 {
|
||||
t.Fatalf("Expected 1 images, %d found", c)
|
||||
}
|
||||
|
||||
// Test delete last one
|
||||
if err := store.Remove(img2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Do more extensive test (ex: with full name, wrong name, with Id, etc)
|
||||
func TestRemoveRegexp(t *testing.T) {
|
||||
store, err := TempStore("test-remove-regexp")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(store)
|
||||
archive, err := fake.FakeTar()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c := countImages(store); c != 0 {
|
||||
t.Fatalf("Expected 0 images, %d found", c)
|
||||
}
|
||||
_, err = store.Create(archive, nil, "foo", "Testing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -11,6 +11,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// FIXME: Remove the Fake package
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
store, err := TempStore("testinit")
|
||||
if err != nil {
|
||||
|
@ -26,6 +28,8 @@ func TestInit(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Do more extensive tests (ex: create multiple, delete, recreate;
|
||||
// create multiple, check the amount of images and paths, etc..)
|
||||
func TestCreate(t *testing.T) {
|
||||
store, err := TempStore("testcreate")
|
||||
if err != nil {
|
||||
|
@ -229,6 +233,8 @@ func TestMountpointDuplicateRoot(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Move this function somewhere else to allow go test to run as non-root
|
||||
// FIXME: Nuke everything afterward (currently leave 2 dir in /tmp)
|
||||
func TestMount(t *testing.T) {
|
||||
store, err := TempStore("test-mount")
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue