Last active
October 2, 2015 11:31
-
-
Save christianklotz/1d01b08027d7866d49f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jsonapi | |
import ( | |
"time" | |
. "github.com/onsi/ginkgo" | |
. "github.com/onsi/gomega" | |
) | |
type TaggedPost struct { | |
SimplePost | |
Tag string | |
} | |
var _ = Describe("Embedded struct types", func() { | |
created, _ := time.Parse(time.RFC3339, "2014-11-10T16:30:48.823Z") | |
post := TaggedPost{ | |
SimplePost{ID: "first", Title: "First Post", Text: "Lipsum", Created: created}, | |
"important", | |
} | |
postMap := map[string]interface{}{ | |
"type": "taggedPost", | |
"id": "first", | |
"attributes": map[string]interface{}{ | |
"title": post.Title, | |
"text": post.Text, | |
"size": 0, | |
"create-date": created, | |
"tag": post.Tag, | |
}, | |
} | |
Context("When marshaling objects with struct composition", func() { | |
It("marshals JSON", func() { | |
i, err := Marshal(post) | |
Expect(err).To(BeNil()) | |
Expect(i).To(Equal(map[string]interface{}{ | |
"data": postMap, | |
})) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment