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

[Elastic Agent] Golden files for program tests #27862

Merged
merged 9 commits into from
Sep 20, 2021

Conversation

ruflin
Copy link
Member

@ruflin ruflin commented Sep 10, 2021

Currently it seems the expected config files for each program were manually generated. This makes adding a new test cumbersome and in case of small changes it means adjusting many files.

This changes the test that it is possible to run with go test . -generate and new golden files are generated. Ideally it also means most of the additional tests become obsolete like how many program files should be generated. To make sure no left over files exist, on -generate all the generated files are first cleaned up.

NOTE: This PR is not complete yet, for example removal of old files is missing and cleanup of generated files. I wanted to discuss the approach first before going further.

Currently it seems the expected config files for each program were manually generated. This makes adding a new test cumbersome and in case of small changes it means adjusting many files.

This changes the test that it is possible to run with `go test . -generate` and new golden files are generated. Ideally it also means most of the additional tests become obsolete like how many program files should be generated. To make sure no left over files exist, on -generate all the generated files are first cleaned up.
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 10, 2021
@ruflin
Copy link
Member Author

ruflin commented Sep 10, 2021

@blakerouse @michalpristas Would be great to get your feedback on this idea.

@ruflin ruflin added the Team:Elastic-Agent Label for the Agent team label Sep 10, 2021
@ruflin ruflin self-assigned this Sep 10, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Sep 10, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 10, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-09-13T06:36:30.210+0000

  • Duration: 77 min 21 sec

  • Commit: ae92c54

Test stats 🧪

Test Results
Failed 0
Passed 7108
Skipped 16
Total 7124

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 7108
Skipped 16
Total 7124

@@ -436,6 +442,16 @@ func TestConfiguration(t *testing.T) {
},
}

// Cleanup all generated files to make sure not having any left overs
if *generateFlag {
generatedFiles, err := filepath.Glob(filepath.Join("testdata", "*.generated.yml"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name? Maybe .golden.yml?

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some what confused on what you are changing here? It seems like you are changing the code to generated the expected results of the tests. To me this will negate the point of the tests. The tests are ensuring that the inputs, match the outputs. The outputs are hand written to ensure that the output is what is expected with the given input.

@ruflin
Copy link
Member Author

ruflin commented Sep 13, 2021

The test files are only generated if the -generate flag is used. Otherwise I agree it would defy the purpose of the tests completely. This is known under golden files test (I picked the first Google result ;-) ).

The problem with the current approach is that it is really cumbersome to add new examples. With the new approach, the first time the generate script can be run and the output can be reviewed. If in the future there is a "mass change" needed, this also make it easier. The important part is that any time the -generate flag is used, the diffs of the files must be carefully reviewed to make sure it is part of the expected change. But that is what a PR review is for.

@ruflin
Copy link
Member Author

ruflin commented Sep 13, 2021

To make this PR easier to review I did not change the old tests and kept them as is. I think we can remove some of these as the new ones replace part of the old ones that have at least one program but we can do this in a follow up PR.

Marking this as ready for review.

@ruflin ruflin marked this pull request as ready for review September 13, 2021 06:37
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping the old tests. I think its good so we don't cause any regressions, until we know for sure this will cover those old tests.

@ruflin ruflin added the backport-v7.16.0 Automated backport with mergify label Sep 20, 2021
@ruflin ruflin merged commit d898e3d into elastic:master Sep 20, 2021
@ruflin ruflin deleted the spec-generate-flag branch September 20, 2021 06:16
mergify bot pushed a commit that referenced this pull request Sep 20, 2021
Currently it seems the expected config files for each program were manually generated. This makes adding a new test cumbersome and in case of small changes it means adjusting many files.

This changes the test that it is possible to run with `go test . -generate` and new golden files are generated. Ideally it also means most of the additional tests become obsolete like how many program files should be generated. To make sure no left over files exist, on -generate all the generated files are first cleaned up.

(cherry picked from commit d898e3d)
ruflin added a commit that referenced this pull request Sep 20, 2021
Currently it seems the expected config files for each program were manually generated. This makes adding a new test cumbersome and in case of small changes it means adjusting many files.

This changes the test that it is possible to run with `go test . -generate` and new golden files are generated. Ideally it also means most of the additional tests become obsolete like how many program files should be generated. To make sure no left over files exist, on -generate all the generated files are first cleaned up.

(cherry picked from commit d898e3d)

Co-authored-by: Nicolas Ruflin <spam@ruflin.com>
v1v added a commit to v1v/beats that referenced this pull request Sep 20, 2021
* upstream/master: (658 commits)
  Add complete k8s metadata through composable provider (elastic#27691)
  Revert "Fix issue where --insecure didn't propogate to Fleet Server ES connection (elastic#27969)" (elastic#27997)
  Remove deprecated kafka fields (elastic#27938)
  [Filebeat] Add Base64 encoded HMAC & UUID template functions to httpjson input (elastic#27873)
  Improve httpjson template function join (elastic#27996)
  Remove kubernetes.container.image alias (elastic#27898)
  [Elastic Agent] Golden files for program tests (elastic#27862)
  [Elastic Agent] Disable modules.d in metricbeat (elastic#27860)
  libbeat/common/seccomp: provide default policy for linux arm64 (elastic#27955)
  Fix logger statement in aws-s3 input (elastic#27982)
  Fix wrong merge (elastic#27976)
  Fix issue where --insecure didn't propogate to Fleet Server ES connection (elastic#27969)
  Forward-port 7.14.2 changelog to master (elastic#27975)
  [Filebeat] Removing duplicate modules (aliases) Observability (elastic#27919)
  Fix path in vagrant windows script (elastic#27966)
  [Filebeat] Removing duplicate modules (aliases) and Cyberark (elastic#27915)
  No changelog for 8.0.0-alpha2 (elastic#27961)
  Add write access to 'url.value' from 'request.transforms'. (elastic#27937)
  Docker: remove deprecated fields (elastic#27933)
  Filebeat: Make all filesets disabled in default configuration (elastic#27762)
  ...
Icedroid pushed a commit to Icedroid/beats that referenced this pull request Nov 1, 2021
Currently it seems the expected config files for each program were manually generated. This makes adding a new test cumbersome and in case of small changes it means adjusting many files.

This changes the test that it is possible to run with `go test . -generate` and new golden files are generated. Ideally it also means most of the additional tests become obsolete like how many program files should be generated. To make sure no left over files exist, on -generate all the generated files are first cleaned up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.16.0 Automated backport with mergify Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants