Skip to content

Commit

Permalink
[Metricbeat] Added mage target to run mocket tests (elastic#11715)
Browse files Browse the repository at this point in the history
  • Loading branch information
sayden authored Apr 11, 2019
1 parent a3856c5 commit 3ba4cc5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions metricbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ package main
import (
"context"
"fmt"
"os"
"regexp"
"strconv"
"time"

"github.com/magefile/mage/mg"
Expand Down Expand Up @@ -93,6 +95,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(ctx context.Context) error {
params := mage.DefaultGoTestUnitArgs()

params.ExtraFlags = []string{"github.com/elastic/beats/metricbeat/mb/testing/data/."}

if module := os.Getenv("MODULE"); module != "" {
params.ExtraFlags = append(params.ExtraFlags, "-module="+module)
}

if generate, _ := strconv.ParseBool(os.Getenv("GENERATE")); generate {
params.ExtraFlags = append(params.ExtraFlags, "-generate")
}

params.Packages = nil

return mage.GoTest(ctx, params)
}

// Fields generates a fields.yml for the Beat.
func Fields() error {
return mage.GenerateFieldsYAML("module")
Expand Down

0 comments on commit 3ba4cc5

Please sign in to comment.