Beispiel #1
0
				v, err := tree.FindArray(data, "array")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal([]interface{}{
					1,
					2,
					"fdsa",
				}))

				f, err := tree.FindString(data, "array.[2]")
				Ω(f).Should(Equal("fdsa"))
			})
		})

		Context("tree.Find()", func() {
			It("should fail if tree.Find() fails", func() {
				v, err := tree.Find(data, "nonexistent")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(BeNil())
			})

			It("should succeed if path exists", func() {
				v, err := tree.Find(data, "string")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal(interface{}("asdf")))
			})
		})
	})

	Context("tree.Numbers", func() {
		Context("Int64()", func() {
			It("fails if the value is not an integer", func() {
Beispiel #2
0
// Returns an interface{} value found in the JSON data
// returned in the response, at `path`
func (r *Response) Val(path string) (interface{}, error) {
	return tree.Find(r.Data, path)
}