[Metricbeat] Added mage target to run mocket tests#11715
[Metricbeat] Added mage target to run mocket tests#11715sayden merged 3 commits intoelastic:masterfrom
Conversation
andrewkroh
left a comment
There was a problem hiding this comment.
Do you have plans/requirements to use this with x-pack/metricbeat?
| 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)) |
There was a problem hiding this comment.
For two strings I'd go with: "-module="+module
| goTestDefaultArgs.ExtraFlags = append(goTestDefaultArgs.ExtraFlags, fmt.Sprintf("-module=%s", module)) | ||
| } | ||
|
|
||
| if generate := os.Getenv("GENERATE"); generate == "true" || generate == "1" { |
There was a problem hiding this comment.
For consistency, use the strconv.ParseBool to parse boolean arguments.
| goTestDefaultArgs.ExtraFlags = append(goTestDefaultArgs.ExtraFlags, "-generate") | ||
| } | ||
|
|
||
| goTestDefaultArgs.Packages = []string{} |
There was a problem hiding this comment.
No need to allocate an empty slice when nil will suffice.
| goTestDefaultArgs.Packages = []string{} | |
| goTestDefaultArgs.Packages = nil |
|
|
||
| goTestDefaultArgs.Packages = []string{} | ||
|
|
||
| return mage.GoTest(context.Background(), goTestDefaultArgs) |
There was a problem hiding this comment.
Define the function as func MockedTests(ctx context.Context) error. Then pass the context from Mage through here.
| // 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() |
There was a problem hiding this comment.
Once you mutate this it will no longer be the default args, so how about just calling it params.
|
We don't have the requirements to implement this in x-pack yet because none of the modules uses HTTP requests to fetch their data. I think it's better to wait until the first module uses http and then work on the |
Split PR from here #11703
Added a mage target called mockedTests to avoid navigating to
beats/metricbeat/mb/testing/datato run tests.