inspect_test.go 1.0 KB

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