inspect_test.go 1011 B

123456789101112131415161718192021222324252627282930313233343536
  1. package image
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "github.com/docker/docker/testutil/environment"
  6. "gotest.tools/v3/assert"
  7. is "gotest.tools/v3/assert/cmp"
  8. "gotest.tools/v3/skip"
  9. )
  10. // Regression test for: https://github.com/moby/moby/issues/45556
  11. func TestImageInspectEmptyTagsAndDigests(t *testing.T) {
  12. skip.If(t, testEnv.DaemonInfo.OSType == "windows", "build-empty-images is not called on Windows")
  13. ctx := setupTest(t)
  14. client := testEnv.APIClient()
  15. danglingID := environment.GetTestDanglingImageId(testEnv)
  16. inspect, raw, err := client.ImageInspectWithRaw(ctx, danglingID)
  17. assert.NilError(t, err)
  18. // Must be a zero length array, not null.
  19. assert.Check(t, is.Len(inspect.RepoTags, 0))
  20. assert.Check(t, is.Len(inspect.RepoDigests, 0))
  21. var rawJson map[string]interface{}
  22. err = json.Unmarshal(raw, &rawJson)
  23. assert.NilError(t, err)
  24. // Check if the raw json is also an array, not null.
  25. assert.Check(t, is.Len(rawJson["RepoTags"], 0))
  26. assert.Check(t, is.Len(rawJson["RepoDigests"], 0))
  27. }