types_test.go 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package resource_test
  2. import (
  3. "encoding/json"
  4. "strings"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. resource "github.com/concourse/registry-image-resource"
  8. )
  9. var _ = Describe("Source", func() {
  10. It("should unmarshal tag int value into a string", func() {
  11. var source resource.Source
  12. raw := []byte(`{ "tag": 0 }`)
  13. err := json.Unmarshal(raw, &source)
  14. Expect(err).ToNot(HaveOccurred())
  15. Expect(source.Tag).To(Equal(resource.Tag("0")))
  16. })
  17. It("should unmarshal tag '' value to latest", func() {
  18. var source resource.Source
  19. raw := []byte(`{ "tag": "" }`)
  20. err := json.Unmarshal(raw, &source)
  21. Expect(err).ToNot(HaveOccurred())
  22. Expect(source.Tag).To(Equal(resource.Tag("latest")))
  23. })
  24. It("should marshal a tag back out to a string", func() {
  25. source := resource.Source{
  26. Tag: "0",
  27. }
  28. json, err := json.Marshal(source)
  29. Expect(err).ToNot(HaveOccurred())
  30. Expect(strings.Contains(string(json[:]), `"tag":"0"`)).To(BeTrue())
  31. })
  32. })