Added new extraction functions to control extensions

New extraction functions added (that just wrap the old ones). The difference here is that the extensions can be included or ignored now. This has been added to address issue #24 where header keys can in fact include an extension prefix.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-05-17 09:33:52 -04:00
parent 08f596058f
commit 230f8fdd02
5 changed files with 171 additions and 15 deletions

View File

@@ -973,6 +973,106 @@ one:
}
func TestExtractMap_NoLookupWithExtensions(t *testing.T) {
yml := `components:`
var idxNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
assert.NoError(t, mErr)
idx := index.NewSpecIndex(&idxNode)
yml = `x-hey: you
one:
x-choo: choo`
var cNode yaml.Node
e := yaml.Unmarshal([]byte(yml), &cNode)
assert.NoError(t, e)
things, err := ExtractMapNoLookupExtensions[*test_Good](cNode.Content[0], idx, true)
assert.NoError(t, err)
assert.Len(t, things, 2)
for k, v := range things {
if k.Value == "x-hey" {
continue
}
assert.Equal(t, "one", k.Value)
assert.Len(t, v.ValueNode.Content, 2)
}
}
func TestExtractMap_NoLookupWithoutExtensions(t *testing.T) {
yml := `components:`
var idxNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
assert.NoError(t, mErr)
idx := index.NewSpecIndex(&idxNode)
yml = `x-hey: you
one:
x-choo: choo`
var cNode yaml.Node
e := yaml.Unmarshal([]byte(yml), &cNode)
assert.NoError(t, e)
things, err := ExtractMapNoLookupExtensions[*test_Good](cNode.Content[0], idx, false)
assert.NoError(t, err)
assert.Len(t, things, 1)
for k, _ := range things {
assert.Equal(t, "one", k.Value)
}
}
func TestExtractMap_WithExtensions(t *testing.T) {
yml := `components:`
var idxNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
assert.NoError(t, mErr)
idx := index.NewSpecIndex(&idxNode)
yml = `x-hey: you
one:
x-choo: choo`
var cNode yaml.Node
e := yaml.Unmarshal([]byte(yml), &cNode)
assert.NoError(t, e)
things, _, _, err := ExtractMapExtensions[*test_Good]("one", cNode.Content[0], idx, true)
assert.NoError(t, err)
assert.Len(t, things, 1)
}
func TestExtractMap_WithoutExtensions(t *testing.T) {
yml := `components:`
var idxNode yaml.Node
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
assert.NoError(t, mErr)
idx := index.NewSpecIndex(&idxNode)
yml = `x-hey: you
one:
x-choo: choo`
var cNode yaml.Node
e := yaml.Unmarshal([]byte(yml), &cNode)
assert.NoError(t, e)
things, _, _, err := ExtractMapExtensions[*test_Good]("one", cNode.Content[0], idx, false)
assert.NoError(t, err)
assert.Len(t, things, 0)
}
func TestExtractMapFlatNoLookup_Ref(t *testing.T) {
yml := `components: