MCPcopy Create free account
hub / github.com/go-openapi/spec / TestJSONLookupItems

Function TestJSONLookupItems

items_test.go:137–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestJSONLookupItems(t *testing.T) {
138 t.Run(`lookup should find "$ref"`, func(t *testing.T) {
139 res, err := testItems.JSONLookup("$ref")
140 require.NoError(t, err)
141 require.NotNil(t, res)
142 require.IsType(t, &Ref{}, res)
143
144 ref, ok := res.(*Ref)
145 require.TrueT(t, ok)
146 assert.Equal(t, MustCreateRef("Dog"), *ref)
147 })
148
149 t.Run(`lookup should find "maximum"`, func(t *testing.T) {
150 var maximum *float64
151 res, err := testItems.JSONLookup("maximum")
152 require.NoError(t, err)
153 require.NotNil(t, res)
154 require.IsType(t, maximum, res)
155
156 var ok bool
157 maximum, ok = res.(*float64)
158 require.TrueT(t, ok)
159 assert.InDeltaT(t, float64(100), *maximum, epsilon)
160 })
161
162 t.Run(`lookup should find "collectionFormat"`, func(t *testing.T) {
163 var f string
164 res, err := testItems.JSONLookup("collectionFormat")
165 require.NoError(t, err)
166 require.NotNil(t, res)
167 require.IsType(t, f, res)
168
169 f, ok := res.(string)
170 require.TrueT(t, ok)
171 assert.EqualT(t, "csv", f)
172 })
173
174 t.Run(`lookup should fail on "unknown"`, func(t *testing.T) {
175 res, err := testItems.JSONLookup("unknown")
176 require.Error(t, err)
177 require.Nil(t, res)
178 })
179}
180
181func TestItemsWithValidation(t *testing.T) {
182 i := new(Items).WithValidations(CommonValidations{MaxLength: conv.Pointer(int64(15))})

Callers

nothing calls this directly

Calls 2

MustCreateRefFunction · 0.85
JSONLookupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…