Tuning parameter exraction for circular ref handling

Lots and lots of variations. means lots of branches to check.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-11-02 15:04:47 -04:00
parent a8a0e1d47f
commit 713aeecdfa
7 changed files with 370 additions and 68 deletions

View File

@@ -57,7 +57,7 @@ func Test_extractRequiredReferenceProperties(t *testing.T) {
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("the-big.yaml#/cheese/thing",
data := extractRequiredReferenceProperties("the-big.yaml#/cheese/thing", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.NotNil(t, data)
@@ -71,7 +71,7 @@ func Test_extractRequiredReferenceProperties_singleFile(t *testing.T) {
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("dingo-bingo-bango.yaml",
data := extractRequiredReferenceProperties("dingo-bingo-bango.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.NotNil(t, data)
@@ -85,7 +85,7 @@ func Test_extractRequiredReferenceProperties_http(t *testing.T) {
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("http://dingo-bingo-bango.yaml/camel.yaml",
data := extractRequiredReferenceProperties("http://dingo-bingo-bango.yaml/camel.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.NotNil(t, data)
@@ -99,12 +99,163 @@ func Test_extractRequiredReferenceProperties_abs(t *testing.T) {
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("/camel.yaml",
data := extractRequiredReferenceProperties("/camel.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.NotNil(t, data)
}
func Test_extractDefinitionRequiredRefProperties_nil(t *testing.T) {
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, ""))
func Test_extractRequiredReferenceProperties_abs3(t *testing.T) {
d := `$ref: oh/pillow.yaml`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("/big/fat/camel.yaml#/milk", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["/big/fat/oh/pillow.yaml"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_rel_full(t *testing.T) {
d := `$ref: "#/a/nice/picture/of/cake"`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("/chalky/milky/camel.yaml#/milk", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["/chalky/milky/camel.yaml#/a/nice/picture/of/cake"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_rel(t *testing.T) {
d := `$ref: oh/camel.yaml#/rum/cake`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("/camel.yaml#/milk", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["/oh/camel.yaml#/rum/cake"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_abs2(t *testing.T) {
d := `$ref: /oh/my/camel.yaml#/rum/cake`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("../flannel.yaml#/milk", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["/oh/my/camel.yaml#/rum/cake"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_http_rel(t *testing.T) {
d := `$ref: my/wet/camel.yaml#/rum/cake`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("http://beer-world.com/lost/in/space.yaml#/vase", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["http://beer-world.com/lost/in/my/wet/camel.yaml#/rum/cake"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_http_rel_nocomponent(t *testing.T) {
d := `$ref: my/wet/camel.yaml`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("http://beer-world.com/lost/in/space.yaml#/vase", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["http://beer-world.com/lost/in/my/wet/camel.yaml"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_nocomponent(t *testing.T) {
d := `$ref: my/wet/camel.yaml`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("#/rotund/cakes", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["my/wet/camel.yaml"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_component_http(t *testing.T) {
d := `$ref: go-to-bed.com/no/more/cake.yaml#/lovely/jam`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("http://bunny-bun-bun.com/no.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["http://bunny-bun-bun.com/go-to-bed.com/no/more/cake.yaml#/lovely/jam"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_nocomponent_http(t *testing.T) {
d := `$ref: go-to-bed.com/no/more/cake.yaml`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("http://bunny-bun-bun.com/no.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["http://bunny-bun-bun.com/go-to-bed.com/no/more/cake.yaml"][0])
assert.NotNil(t, data)
}
func Test_extractRequiredReferenceProperties_nocomponent_http2(t *testing.T) {
d := `$ref: go-to-bed.com/no/more/cake.yaml`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(d), &rootNode)
props := make(map[string][]string)
data := extractRequiredReferenceProperties("/why.yaml", nil,
rootNode.Content[0], "cakes", props)
assert.Len(t, props, 1)
assert.Equal(t, "cakes", props["/go-to-bed.com/no/more/cake.yaml"][0])
assert.NotNil(t, data)
}
func Test_extractDefinitionRequiredRefProperties_nil(t *testing.T) {
assert.Nil(t, extractDefinitionRequiredRefProperties(nil, nil, "", nil))
}