diff --git a/tests/metadata_test.go b/tests/metadata_test.go index 8d9addb..dd06c1f 100644 --- a/tests/metadata_test.go +++ b/tests/metadata_test.go @@ -3,6 +3,7 @@ package fargo_test // MIT Licensed (see README.md) - Copyright (c) 2013 Hudl <@Hudl> import ( + "encoding/xml" "github.com/hudl/fargo" . "github.com/smartystreets/goconvey/convey" "strconv" @@ -58,3 +59,28 @@ func TestGetFloat(t *testing.T) { }) }) } + +func TestSerializeMeta(t *testing.T) { + Convey("Given an instance", t, func() { + instance := new(fargo.Instance) + Convey("With metadata", func() { + instance.SetMetadataString("test", "value") + Convey("Serializing results in correct JSON", func() { + b, err := instance.Metadata.MarshalJSON() + So(err, ShouldBeNil) + So(string(b), ShouldEqual, "{\"test\":\"value\"}") + }) + Convey("Serializing results in correct XML", func() { + b, err := xml.Marshal(instance.Metadata) + So(err, ShouldBeNil) + So(string(b), ShouldEqual, "value") + }) + Convey("Blank metadata results in blank XML", func() { + metadata := new(fargo.InstanceMetadata) + b, err := xml.Marshal(metadata) + So(err, ShouldBeNil) + So(string(b), ShouldEqual, "") + }) + }) + }) +}