mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1089 from dotcloud/multiple_test_images-fix
- Tests: Fix unit tests when there is more than one tag within the test image
This commit is contained in:
commit
ead9cefadb
3 changed files with 49 additions and 21 deletions
52
api_test.go
52
api_test.go
|
@ -137,6 +137,11 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
initialImages, err := srv.Images(true, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// all=0
|
// all=0
|
||||||
req, err := http.NewRequest("GET", "/images/json?all=0", nil)
|
req, err := http.NewRequest("GET", "/images/json?all=0", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -154,12 +159,19 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 1 {
|
if len(images) != len(initialImages) {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images))
|
t.Errorf("Excepted %d image, %d found", len(initialImages), len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
if images[0].Repository != unitTestImageName {
|
found := false
|
||||||
t.Errorf("Excepted image %s, %s found", unitTestImageName, images[0].Repository)
|
for _, img := range images {
|
||||||
|
if img.Repository == unitTestImageName {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Errorf("Excepted image %s, %+v found", unitTestImageName, images)
|
||||||
}
|
}
|
||||||
|
|
||||||
r2 := httptest.NewRecorder()
|
r2 := httptest.NewRecorder()
|
||||||
|
@ -179,18 +191,25 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images2) != 1 {
|
if len(images2) != len(initialImages) {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images2))
|
t.Errorf("Excepted %d image, %d found", len(initialImages), len(images2))
|
||||||
}
|
}
|
||||||
|
|
||||||
if images2[0].ID != GetTestImage(runtime).ID {
|
found = false
|
||||||
t.Errorf("Retrieved image Id differs, expected %s, received %s", GetTestImage(runtime).ID, images2[0].ID)
|
for _, img := range images2 {
|
||||||
|
if img.ID == GetTestImage(runtime).ID {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Errorf("Retrieved image Id differs, expected %s, received %+v", GetTestImage(runtime).ID, images2)
|
||||||
}
|
}
|
||||||
|
|
||||||
r3 := httptest.NewRecorder()
|
r3 := httptest.NewRecorder()
|
||||||
|
|
||||||
// filter=a
|
// filter=a
|
||||||
req3, err := http.NewRequest("GET", "/images/json?filter=a", nil)
|
req3, err := http.NewRequest("GET", "/images/json?filter=aaaaaaaaaa", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -205,7 +224,7 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images3) != 0 {
|
if len(images3) != 0 {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images3))
|
t.Errorf("Excepted 0 image, %d found", len(images3))
|
||||||
}
|
}
|
||||||
|
|
||||||
r4 := httptest.NewRecorder()
|
r4 := httptest.NewRecorder()
|
||||||
|
@ -1310,6 +1329,11 @@ func TestDeleteImages(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
initialImages, err := srv.Images(false, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := srv.runtime.repositories.Set("test", "test", unitTestImageName, true); err != nil {
|
if err := srv.runtime.repositories.Set("test", "test", unitTestImageName, true); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -1319,8 +1343,8 @@ func TestDeleteImages(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 2 {
|
if len(images) != len(initialImages)+1 {
|
||||||
t.Errorf("Excepted 2 images, %d found", len(images))
|
t.Errorf("Excepted %d images, %d found", len(initialImages)+1, len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", "/images/test:test", nil)
|
req, err := http.NewRequest("DELETE", "/images/test:test", nil)
|
||||||
|
@ -1348,8 +1372,8 @@ func TestDeleteImages(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 1 {
|
if len(images) != len(initialImages) {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images))
|
t.Errorf("Excepted %d image, %d found", len(initialImages), len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if c := runtime.Get(container.Id); c != nil {
|
/* if c := runtime.Get(container.Id); c != nil {
|
||||||
|
|
|
@ -97,7 +97,6 @@ func init() {
|
||||||
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil {
|
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, utils.NewStreamFormatter(false), nil); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn a Daemon
|
// Spawn a Daemon
|
||||||
go func() {
|
go func() {
|
||||||
if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil {
|
if err := ListenAndServe(testDaemonProto, testDaemonAddr, srv, os.Getenv("DEBUG") != ""); err != nil {
|
||||||
|
|
|
@ -13,6 +13,11 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
initialImages, err := srv.Images(false, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
if err := srv.runtime.repositories.Set("utest", "tag1", unitTestImageName, false); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -25,8 +30,8 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 3 {
|
if len(images) != len(initialImages)+2 {
|
||||||
t.Errorf("Excepted 3 images, %d found", len(images))
|
t.Errorf("Excepted %d images, %d found", len(initialImages)+2, len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := srv.ImageDelete("utest/docker:tag2", true); err != nil {
|
if _, err := srv.ImageDelete("utest/docker:tag2", true); err != nil {
|
||||||
|
@ -38,8 +43,8 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 2 {
|
if len(images) != len(initialImages)+1 {
|
||||||
t.Errorf("Excepted 2 images, %d found", len(images))
|
t.Errorf("Excepted %d images, %d found", len(initialImages)+1, len(images))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := srv.ImageDelete("utest:tag1", true); err != nil {
|
if _, err := srv.ImageDelete("utest:tag1", true); err != nil {
|
||||||
|
@ -51,8 +56,8 @@ func TestContainerTagImageDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(images) != 1 {
|
if len(images) != len(initialImages) {
|
||||||
t.Errorf("Excepted 1 image, %d found", len(images))
|
t.Errorf("Excepted %d image, %d found", len(initialImages), len(images))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue