github.com/snyk/vervet/v4@v4.27.2/ref_index_test.go (about) 1 package vervet_test 2 3 import ( 4 "testing" 5 6 qt "github.com/frankban/quicktest" 7 8 "github.com/snyk/vervet/v4" 9 "github.com/snyk/vervet/v4/testdata" 10 ) 11 12 func TestRefIndexSource(t *testing.T) { 13 c := qt.New(t) 14 doc, err := vervet.NewDocumentFile(testdata.Path("resources/_examples/hello-world/2021-06-01/spec.yaml")) 15 c.Assert(err, qt.IsNil) 16 ix, err := vervet.NewRefIndex(doc.T) 17 c.Assert(err, qt.IsNil) 18 19 c.Assert(ix.HasRef("#/components/schemas/HelloWorld"), qt.IsTrue) 20 c.Assert(ix.HasRef("#/components/headers/DeprecationHeader"), qt.IsFalse) 21 c.Assert(ix.HasRef("#/components/schemas/Nope"), qt.IsFalse) 22 } 23 24 func TestRefIndexCompiled(t *testing.T) { 25 c := qt.New(t) 26 doc, err := vervet.NewDocumentFile(testdata.Path("output/2021-06-01~experimental/spec.json")) 27 c.Assert(err, qt.IsNil) 28 ix, err := vervet.NewRefIndex(doc.T) 29 c.Assert(err, qt.IsNil) 30 31 c.Assert(ix.HasRef("#/components/schemas/HelloWorld"), qt.IsTrue) 32 c.Assert(ix.HasRef("#/components/headers/DeprecationHeader"), qt.IsTrue) 33 c.Assert(ix.HasRef("#/components/schemas/Nope"), qt.IsFalse) 34 }