Beispiel #1
0
			It("should fail if path is not a bool", func() {
				v, err := tree.FindBool(data, "number")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(false))
			})

			It("should succeed if path exists and is boolean", func() {
				v, err := tree.FindBool(data, "boolean")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal(true))
			})
		})

		Context("tree.FindMap()", func() {
			It("should fail if tree.Find() fails", func() {
				v, err := tree.FindMap(data, "nonexistent")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(map[string]interface{}{}))
			})

			It("should fail if path is not a map", func() {
				v, err := tree.FindMap(data, "number")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(map[string]interface{}{}))
			})

			It("should succeed if path exists and is a map", func() {
				v, err := tree.FindMap(data, "map")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal(map[string]interface{}{
					"k": "v",
Beispiel #2
0
// Returns a map[string]interface{}-typed value found in the JSON data
// returned in the response, at `path`
func (r *Response) MapVal(path string) (map[string]interface{}, error) {
	return tree.FindMap(r.Data, path)
}