MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestObject_Find

Function TestObject_Find

object_test.go:1794–1950  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1792}
1793
1794func TestObject_Find(t *testing.T) {
1795 t.Run("elements of same type", func(t *testing.T) {
1796 reporter := newMockReporter(t)
1797 object := NewObject(reporter, map[string]interface{}{
1798 "foo": "bar",
1799 "baz": "qux",
1800 "quux": "corge",
1801 })
1802
1803 foundValue := object.Find(func(key string, value *Value) bool {
1804 return key == "baz"
1805 })
1806
1807 assert.Equal(t, "qux", foundValue.Raw())
1808 assert.Equal(t, object.Raw(), map[string]interface{}{
1809 "foo": "bar",
1810 "baz": "qux",
1811 "quux": "corge",
1812 })
1813
1814 foundValue.chain.assert(t, success)
1815 object.chain.assert(t, success)
1816 })
1817
1818 t.Run("elements of different types", func(t *testing.T) {
1819 reporter := newMockReporter(t)
1820 object := NewObject(reporter, map[string]interface{}{
1821 "foo": "bar",
1822 "baz": true,
1823 "qux": -1,
1824 "quux": 2,
1825 })
1826
1827 foundValue := object.Find(func(key string, value *Value) bool {
1828 n := value.Number().Raw()
1829 return n > 1
1830 })
1831
1832 assert.Equal(t, 2.0, foundValue.Raw())
1833 assert.Equal(t, object.Raw(), map[string]interface{}{
1834 "foo": "bar",
1835 "baz": true,
1836 "qux": -1.0,
1837 "quux": 2.0,
1838 })
1839
1840 foundValue.chain.assert(t, success)
1841 object.chain.assert(t, success)
1842 })
1843
1844 t.Run("no match", func(t *testing.T) {
1845 reporter := newMockReporter(t)
1846 object := NewObject(reporter, map[string]interface{}{
1847 "foo": "bar",
1848 "baz": true,
1849 "qux": -1,
1850 "quux": 2,
1851 })

Callers

nothing calls this directly

Calls 9

FindMethod · 0.95
RawMethod · 0.95
newMockReporterFunction · 0.85
NewObjectFunction · 0.85
assertMethod · 0.80
EqualMethod · 0.45
RawMethod · 0.45
NumberMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…