Skip to content

Commit ee755e9

Browse files
committed
Add test for nested types - included spec version
1 parent 7c09c48 commit ee755e9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

internal/fields/mappings_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
)
1515

1616
func TestComparingMappings(t *testing.T) {
17+
defaultSpecVersion := "3.3.0"
1718
cases := []struct {
1819
title string
1920
preview map[string]any
2021
actual map[string]any
2122
schema []FieldDefinition
23+
spec string
2224
expectedErrors []string
2325
}{
2426
{
@@ -502,6 +504,7 @@ func TestComparingMappings(t *testing.T) {
502504
External: "ecs",
503505
},
504506
},
507+
spec: "1.0.0",
505508
expectedErrors: []string{
506509
`field "error.field" is undefined: missing definition for path`,
507510
// should status.field return error ? or should it be ignored?
@@ -593,12 +596,38 @@ func TestComparingMappings(t *testing.T) {
593596
},
594597
expectedErrors: []string{},
595598
},
599+
{
600+
title: "skip nested types before spec 3.0.1",
601+
preview: map[string]any{
602+
"foo": map[string]any{
603+
"type": "nested",
604+
},
605+
},
606+
actual: map[string]any{
607+
"foo": map[string]any{
608+
"type": "nested",
609+
"properties": map[string]any{
610+
"bar": map[string]any{
611+
"type": "long",
612+
},
613+
},
614+
},
615+
},
616+
spec: "3.0.0",
617+
schema: []FieldDefinition{},
618+
expectedErrors: []string{},
619+
},
596620
}
597621

598622
for _, c := range cases {
599623
t.Run(c.title, func(t *testing.T) {
600624
logger.EnableDebugMode()
625+
specVersion := defaultSpecVersion
626+
if c.spec != "" {
627+
specVersion = c.spec
628+
}
601629
v, err := CreateValidatorForMappings("", nil,
630+
WithMappingValidatorSpecVersion(specVersion),
602631
WithMappingValidatorFallbackSchema(c.schema),
603632
WithMappingValidatorDisabledDependencyManagement(),
604633
)

0 commit comments

Comments
 (0)