GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imageentry_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package registry
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/weaveworks/flux/image"
  8. )
  9. // Check that the ImageEntry type can be round-tripped via JSON.
  10. func TestImageEntryRoundtrip(t *testing.T) {
  11. test := func(t *testing.T, entry ImageEntry) {
  12. bytes, err := json.Marshal(entry)
  13. assert.NoError(t, err)
  14. var entry2 ImageEntry
  15. assert.NoError(t, json.Unmarshal(bytes, &entry2))
  16. assert.Equal(t, entry, entry2)
  17. }
  18. ref, err := image.ParseRef("docker.io/weaveworks/flux:1.0.0")
  19. assert.NoError(t, err)
  20. info := image.Info{
  21. ID: ref,
  22. CreatedAt: time.Now().UTC(), // to UTC since we unmarshal times in UTC
  23. }
  24. entry := ImageEntry{
  25. Info: info,
  26. }
  27. t.Run("With an info", func(t *testing.T) { test(t, entry) })
  28. t.Run("With an excluded reason", func(t *testing.T) {
  29. entry.Info = image.Info{}
  30. entry.ExcludedReason = "just because"
  31. test(t, entry)
  32. })
  33. }
  34. // Check that existing entries, which are image.Info, will parse into
  35. // the ImageEntry struct.
  36. func TestImageInfoParsesAsEntry(t *testing.T) {
  37. ref, err := image.ParseRef("docker.io/weaveworks/flux:1.0.0")
  38. assert.NoError(t, err)
  39. info := image.Info{
  40. ID: ref,
  41. CreatedAt: time.Now().UTC(), // to UTC since we unmarshal times in UTC
  42. }
  43. bytes, err := json.Marshal(info)
  44. assert.NoError(t, err)
  45. var entry2 ImageEntry
  46. assert.NoError(t, json.Unmarshal(bytes, &entry2))
  47. assert.Equal(t, info, entry2.Info)
  48. }