Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/pipeline.trigger.integration.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ echo " - build/test-coverage/coverage-*.xml" # these files should not b
# Add steps to test validation method mappings
while IFS= read -r -d '' package ; do
package_name=$(basename "${package}")
echo " - label: \":go: Integration test: ${package_name} (just validate mappings)\""
echo " - label: \":go: Integration test: ${package_name} (validate mappings)\""
echo " key: \"integration-parallel-${package_name}-agent-validate-mappings\""
echo " command: ./.buildkite/scripts/integration_tests.sh -t test-check-packages-parallel -p ${package_name}"
echo " env:"
Expand Down
20 changes: 20 additions & 0 deletions internal/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ func (c *Client) SimulateIndexTemplate(ctx context.Context, indexTemplateName st
return nil, nil, fmt.Errorf("error unmarshaling mappings: %w", err)
}

// In case there are no dynamic templates, set an empty array
if string(preview.Template.Mappings.DynamicTemplates) == "" {
preview.Template.Mappings.DynamicTemplates = []byte("[]")
}

// In case there are no mappings defined, set an empty map
if string(preview.Template.Mappings.Properties) == "" {
preview.Template.Mappings.Properties = []byte("{}")
}

return preview.Template.Mappings.DynamicTemplates, preview.Template.Mappings.Properties, nil
}

Expand Down Expand Up @@ -403,5 +413,15 @@ func (c *Client) DataStreamMappings(ctx context.Context, dataStreamName string)
mappingsDefinition = v.Mappings
}

// In case there are no dynamic templates, set an empty array
if string(mappingsDefinition.DynamicTemplates) == "" {
mappingsDefinition.DynamicTemplates = []byte("[]")
}

// In case there are no mappings defined, set an empty map
if string(mappingsDefinition.Properties) == "" {
mappingsDefinition.Properties = []byte("{}")
}

return mappingsDefinition.DynamicTemplates, mappingsDefinition.Properties, nil
}
20 changes: 8 additions & 12 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,11 @@ var (
type fieldValidationMethod int

const (
allMethods fieldValidationMethod = iota
fieldsMethod
fieldsMethod fieldValidationMethod = iota
mappingsMethod
)

var validationMethods = map[string]fieldValidationMethod{
"all": allMethods,
"fields": fieldsMethod,
"mappings": mappingsMethod,
}
Expand Down Expand Up @@ -1632,13 +1630,11 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
return result.WithErrorf("creating fields validator for data stream failed (path: %s): %w", r.dataStreamPath, err)
}

if r.fieldValidationMethod == allMethods || r.fieldValidationMethod == fieldsMethod {
if errs := validateFields(scenario.docs, fieldsValidator); len(errs) > 0 {
return result.WithError(testrunner.ErrTestCaseFailed{
Reason: fmt.Sprintf("one or more errors found in documents stored in %s data stream", scenario.dataStream),
Details: errs.Error(),
})
}
if errs := validateFields(scenario.docs, fieldsValidator); len(errs) > 0 {
return result.WithError(testrunner.ErrTestCaseFailed{
Reason: fmt.Sprintf("one or more errors found in documents stored in %s data stream", scenario.dataStream),
Details: errs.Error(),
})
}

stackVersion, err := semver.NewVersion(r.stackVersion.Number)
Expand All @@ -1651,8 +1647,8 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
return result.WithError(err)
}

if r.fieldValidationMethod == allMethods || r.fieldValidationMethod == mappingsMethod {
logger.Warn("Validate mappings found (technical preview)")
if r.fieldValidationMethod == mappingsMethod {
logger.Warn("Validation based on mappings enabled (technical preview)")
exceptionFields := listExceptionFields(scenario.docs, fieldsValidator)

mappingsValidator, err := fields.CreateValidatorForMappings(r.esClient,
Expand Down