docker_cli_images_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "strings"
  6. "testing"
  7. "time"
  8. )
  9. func TestImagesEnsureImageIsListed(t *testing.T) {
  10. imagesCmd := exec.Command(dockerBinary, "images")
  11. out, _, err := runCommandWithOutput(imagesCmd)
  12. errorOut(err, t, fmt.Sprintf("listing images failed with errors: %v", err))
  13. if !strings.Contains(out, "busybox") {
  14. t.Fatal("images should've listed busybox")
  15. }
  16. logDone("images - busybox should be listed")
  17. }
  18. func TestImagesOrderedByCreationDate(t *testing.T) {
  19. defer deleteImages("order:test_a")
  20. defer deleteImages("order:test_c")
  21. defer deleteImages("order:test_b")
  22. id1, err := buildImage("order:test_a",
  23. `FROM scratch
  24. MAINTAINER dockerio1`, true)
  25. if err != nil {
  26. t.Fatal(err)
  27. }
  28. time.Sleep(time.Second)
  29. id2, err := buildImage("order:test_c",
  30. `FROM scratch
  31. MAINTAINER dockerio2`, true)
  32. if err != nil {
  33. t.Fatal(err)
  34. }
  35. time.Sleep(time.Second)
  36. id3, err := buildImage("order:test_b",
  37. `FROM scratch
  38. MAINTAINER dockerio3`, true)
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "images", "-q", "--no-trunc"))
  43. errorOut(err, t, fmt.Sprintf("listing images failed with errors: %v", err))
  44. imgs := strings.Split(out, "\n")
  45. if imgs[0] != id3 {
  46. t.Fatalf("First image must be %s, got %s", id3, imgs[0])
  47. }
  48. if imgs[1] != id2 {
  49. t.Fatalf("Second image must be %s, got %s", id2, imgs[1])
  50. }
  51. if imgs[2] != id1 {
  52. t.Fatalf("Third image must be %s, got %s", id1, imgs[2])
  53. }
  54. logDone("images - ordering by creation date")
  55. }