contextmetadata_test.go 961 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package store
  2. import (
  3. "encoding/json"
  4. "testing"
  5. . "github.com/onsi/gomega"
  6. "github.com/stretchr/testify/suite"
  7. )
  8. type ContextTestSuite struct {
  9. suite.Suite
  10. }
  11. func (suite *ContextTestSuite) TestDockerContextMetadataKeepAdditionalFields() {
  12. c := ContextMetadata{
  13. Description: "test",
  14. Type: "aci",
  15. StackOrchestrator: "swarm",
  16. AdditionalFields: map[string]interface{}{
  17. "foo": "bar",
  18. },
  19. }
  20. jsonBytes, err := json.Marshal(c)
  21. Expect(err).To(BeNil())
  22. Expect(string(jsonBytes)).To(Equal(`{"Description":"test","StackOrchestrator":"swarm","Type":"aci","foo":"bar"}`))
  23. var c2 ContextMetadata
  24. err = json.Unmarshal(jsonBytes, &c2)
  25. Expect(err).To(BeNil())
  26. Expect(c2.AdditionalFields["foo"]).To(Equal("bar"))
  27. Expect(c2.Type).To(Equal("aci"))
  28. Expect(c2.StackOrchestrator).To(Equal("swarm"))
  29. Expect(c2.Description).To(Equal("test"))
  30. }
  31. func TestPs(t *testing.T) {
  32. RegisterTestingT(t)
  33. suite.Run(t, new(ContextTestSuite))
  34. }