Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/testrunner/runners/pipeline: output documents with fields in a normalized order #644

Merged
merged 1 commit into from
Jan 13, 2022
Merged
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
18 changes: 17 additions & 1 deletion internal/testrunner/runners/pipeline/test_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,29 @@ func unmarshalTestResult(body []byte) (*testResult, error) {
func marshalTestResultDefinition(result *testResult) ([]byte, error) {
var trd testResultDefinition
trd.Expected = result.events
body, err := json.MarshalIndent(&trd, "", " ")
body, err := marshalNormalizedJSON(trd)
if err != nil {
return nil, errors.Wrap(err, "marshalling test result definition failed")
}
return body, nil
}

// marshalNormalizedJSON marshals test results ensuring that field
// order remains consistent independent of field order returned by
// ES to minimize diff noise during changes.
func marshalNormalizedJSON(v testResultDefinition) ([]byte, error) {
msg, err := json.Marshal(v)
if err != nil {
return msg, err
}
var obj interface{}
err = json.Unmarshal(msg, &obj)
if err != nil {
return msg, err
}
return json.MarshalIndent(obj, "", " ")
}

func expectedTestResultFile(testFile string) string {
return fmt.Sprintf("%s%s", testFile, expectedTestResultSuffix)
}