MCPcopy Index your code
hub / github.com/go-openapi/jsonpointer / TestGetSingle

Function TestGetSingle

pointer_test.go:159–219  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestGetSingle(t *testing.T) {
160 t.Parallel()
161
162 const key = "obj"
163
164 t.Run("should create a new JSON pointer", func(t *testing.T) {
165 const in = "/" + key
166
167 _, err := New(in)
168 require.NoError(t, err)
169 })
170
171 t.Run(fmt.Sprintf("should find token %q in JSON", key), func(t *testing.T) {
172 result, _, err := GetForToken(testDocumentJSON(t), key)
173 require.NoError(t, err)
174 assert.Len(t, result, testNodeObjNBItems())
175 })
176
177 t.Run(fmt.Sprintf("should find token %q in type alias interface", key), func(t *testing.T) {
178 type alias any
179 var in alias = testDocumentJSON(t)
180
181 result, _, err := GetForToken(in, key)
182 require.NoError(t, err)
183 assert.Len(t, result, testNodeObjNBItems())
184 })
185
186 t.Run(fmt.Sprintf("should find token %q in pointer to interface", key), func(t *testing.T) {
187 in := testDocumentJSON(t)
188
189 result, _, err := GetForToken(&in, key)
190 require.NoError(t, err)
191 assert.Len(t, result, testNodeObjNBItems())
192 })
193
194 t.Run(`should NOT find token "Obj" in struct`, func(t *testing.T) {
195 result, _, err := GetForToken(testStructJSONDoc(t), "Obj")
196 require.Error(t, err)
197 assert.Nil(t, result)
198 })
199
200 t.Run(`should not find token "Obj2" in struct`, func(t *testing.T) {
201 result, _, err := GetForToken(testStructJSONDoc(t), "Obj2")
202 require.Error(t, err)
203 assert.Nil(t, result)
204 })
205
206 t.Run("should not find token in nil", func(t *testing.T) {
207 result, _, err := GetForToken(nil, key)
208 require.Error(t, err)
209 assert.Nil(t, result)
210 })
211
212 t.Run("should not find token in nil interface", func(t *testing.T) {
213 var in any
214
215 result, _, err := GetForToken(in, key)
216 require.Error(t, err)

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
GetForTokenFunction · 0.85
testDocumentJSONFunction · 0.85
testNodeObjNBItemsFunction · 0.85
testStructJSONDocFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…