-
Notifications
You must be signed in to change notification settings - Fork 518
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
Introduce approvaltest module #4112
Conversation
💔 Tests FailedExpand to view the summary
Build stats
Test stats 🧪
Test errorsExpand to view the tests failures
Steps errorsExpand to view the steps failures
Log outputExpand to view the last 100 lines of log output
|
22fdef6
to
875f630
Compare
We move tests/approvals and tests/scripts/approvals.go intoa new module, github.com/elastic/apm-server/approvaltest. This new module will be used by both apm-server (integration tests) and the systemtest module. We also reduce the API surface area to two functions: ApproveJSON, and ApproveEventDocs. The ApproveJSON function can be used for approving arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended for approving JSON-encoded Elasticsearch event documents. To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which encode events using the libbeat Elasticsearch output. In some tests we previously used the libbeat JSON codec directly, which led to @metadata being included in diffs. The output removes @metadata, hence it no longer features in our approval diffs.
- Since we now use the Elasticsearch output, rather than directly using the libbeat JSON codec, `@metadata` is no longer part of the diff, and `@timestamp` is encoded slightly differently. - For dynamic fields like `profile.id`, we now replace the value with a known string ("dynamic") rather than ignoring the field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you for pulling out in a dedicated module.
I can confirm that the bug, that led to not removing .received
files, is also fixed with these improvements.
* Introduce new approvaltest module We move tests/approvals and tests/scripts/approvals.go intoa new module, github.com/elastic/apm-server/approvaltest. This new module will be used by both apm-server (integration tests) and the systemtest module. We also reduce the API surface area to two functions: ApproveJSON, and ApproveEventDocs. The ApproveJSON function can be used for approving arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended for approving JSON-encoded Elasticsearch event documents. To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which encode events using the libbeat Elasticsearch output. In some tests we previously used the libbeat JSON codec directly, which led to @metadata being included in diffs. The output removes @metadata, hence it no longer features in our approval diffs. * Update approved files - Since we now use the Elasticsearch output, rather than directly using the libbeat JSON codec, `@metadata` is no longer part of the diff, and `@timestamp` is encoded slightly differently. - For dynamic fields like `profile.id`, we now replace the value with a known string ("dynamic") rather than ignoring the field. * .ci/docker/golang-mage: support multiple modules
* Introduce new approvaltest module We move tests/approvals and tests/scripts/approvals.go intoa new module, github.com/elastic/apm-server/approvaltest. This new module will be used by both apm-server (integration tests) and the systemtest module. We also reduce the API surface area to two functions: ApproveJSON, and ApproveEventDocs. The ApproveJSON function can be used for approving arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended for approving JSON-encoded Elasticsearch event documents. To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which encode events using the libbeat Elasticsearch output. In some tests we previously used the libbeat JSON codec directly, which led to @metadata being included in diffs. The output removes @metadata, hence it no longer features in our approval diffs. * Update approved files - Since we now use the Elasticsearch output, rather than directly using the libbeat JSON codec, `@metadata` is no longer part of the diff, and `@timestamp` is encoded slightly differently. - For dynamic fields like `profile.id`, we now replace the value with a known string ("dynamic") rather than ignoring the field. * .ci/docker/golang-mage: support multiple modules
* Introduce approvaltest module (#4112) * Introduce new approvaltest module We move tests/approvals and tests/scripts/approvals.go intoa new module, github.com/elastic/apm-server/approvaltest. This new module will be used by both apm-server (integration tests) and the systemtest module. We also reduce the API surface area to two functions: ApproveJSON, and ApproveEventDocs. The ApproveJSON function can be used for approving arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended for approving JSON-encoded Elasticsearch event documents. To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which encode events using the libbeat Elasticsearch output. In some tests we previously used the libbeat JSON codec directly, which led to @metadata being included in diffs. The output removes @metadata, hence it no longer features in our approval diffs. * Update approved files - Since we now use the Elasticsearch output, rather than directly using the libbeat JSON codec, `@metadata` is no longer part of the diff, and `@timestamp` is encoded slightly differently. - For dynamic fields like `profile.id`, we now replace the value with a known string ("dynamic") rather than ignoring the field. * .ci/docker/golang-mage: support multiple modules * tests: fix docker-system-tests (#4123) Copy in approvaltest/go.mod (and systemtest/go.mod for good measure) to fix `go mod download` at the top level. Also run `go mod download` for the sub-modules, to speed up repeat runs of docker-system-tests.
Motivation/summary
Move tests/approvals and tests/scripts/approvals.go into a new module,
github.com/elastic/apm-server/approvaltest. This new module will be used
by both apm-server (in integration tests) and the systemtest module,
enabling us to have those two modules not import from one another.
We also reduce the approvals API surface area to two functions: ApproveJSON,
and ApproveEventDocs. The ApproveJSON function can be used for approving
arbitrary JSON-encoded values, while ApproveEventDocs is specifically intended
for approving JSON-encoded Elasticsearch event documents.
To enable the API reduction, we introduce beatertest.EncodeEventDoc(s), which
encode events using the libbeat Elasticsearch output. In some tests we previously
used the libbeat JSON codec directly, which led to
@metadata
being included indiffs. The output removes
@metadata
, hence it no longer features in our approvaldiffs.
For dynamic fields like
profile.id
, we now replace the value with a known string("dynamic") rather than ignoring the field completely. This minimises the diffs of
.approved.json
files, and also allows us to detect added/removed fields.Checklist
- [ ] I have updated CHANGELOG.asciidocI have considered changes for:
- [ ] documentation- [ ] logging (add log lines, choose appropriate log selector, etc.)- [ ] metrics and monitoring (create issue for Kibana team to add metrics to visualizations, e.g. Kibana#44001)- [ ] telemetry- [ ] Elasticsearch Service (https://cloud.elastic.co)- [ ] Elastic Cloud Enterprise (https://www.elastic.co/products/ece)- [ ] Elastic Cloud on Kubernetes (https://www.elastic.co/elastic-cloud-kubernetes)How to test these changes
make test
Related issues
See #4084 (comment)