types_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 string value into a string", func() {
  18. var source resource.Source
  19. raw := []byte(`{ "tag": "foo" }`)
  20. err := json.Unmarshal(raw, &source)
  21. Expect(err).ToNot(HaveOccurred())
  22. Expect(source.Tag).To(Equal(resource.Tag("foo")))
  23. })
  24. It("should unmarshal tag '' value to latest", func() {
  25. var source resource.Source
  26. raw := []byte(`{ "tag": "" }`)
  27. err := json.Unmarshal(raw, &source)
  28. Expect(err).ToNot(HaveOccurred())
  29. Expect(source.Tag).To(Equal(resource.Tag("latest")))
  30. })
  31. It("should marshal a tag back out to a string", func() {
  32. source := resource.Source{
  33. Tag: "0",
  34. }
  35. json, err := json.Marshal(source)
  36. Expect(err).ToNot(HaveOccurred())
  37. Expect(strings.Contains(string(json[:]), `"tag":"0"`)).To(BeTrue())
  38. })
  39. })