-
Notifications
You must be signed in to change notification settings - Fork 5k
[Metricbeat] Added mage target to run mocket tests #11715
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,7 @@ package main | |||||
| import ( | ||||||
| "context" | ||||||
| "fmt" | ||||||
| "os" | ||||||
| "regexp" | ||||||
| "time" | ||||||
|
|
||||||
|
|
@@ -93,6 +94,27 @@ func Update() error { | |||||
| return sh.Run("make", "update") | ||||||
| } | ||||||
|
|
||||||
| // MockedTests runs the HTTP tests using the mocked data inside each {module}/{metricset}/testdata folder. | ||||||
| // Use MODULE={module_name} to run only mocked tests with a single module. | ||||||
| // Use GENERATE=true or GENERATE=1 to regenerate JSON files. | ||||||
| func MockedTests() error { | ||||||
| goTestDefaultArgs := mage.DefaultGoTestUnitArgs() | ||||||
|
|
||||||
| goTestDefaultArgs.ExtraFlags = []string{"github.com/elastic/beats/metricbeat/mb/testing/data/."} | ||||||
|
|
||||||
| if module := os.Getenv("MODULE"); module != "" { | ||||||
| goTestDefaultArgs.ExtraFlags = append(goTestDefaultArgs.ExtraFlags, fmt.Sprintf("-module=%s", module)) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For two strings I'd go with: |
||||||
| } | ||||||
|
|
||||||
| if generate := os.Getenv("GENERATE"); generate == "true" || generate == "1" { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! |
||||||
| goTestDefaultArgs.ExtraFlags = append(goTestDefaultArgs.ExtraFlags, "-generate") | ||||||
| } | ||||||
|
|
||||||
| goTestDefaultArgs.Packages = []string{} | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to allocate an empty slice when
Suggested change
|
||||||
|
|
||||||
| return mage.GoTest(context.Background(), goTestDefaultArgs) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define the function as |
||||||
| } | ||||||
|
|
||||||
| // Fields generates a fields.yml for the Beat. | ||||||
| func Fields() error { | ||||||
| return mage.GenerateFieldsYAML("module") | ||||||
|
|
||||||
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.
Once you mutate this it will no longer be the default args, so how about just calling it
params.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.
Good point