diff --git a/.ci/scripts/build-test.sh b/.ci/scripts/build-test.sh index b399a4f548..89ae6c9342 100755 --- a/.ci/scripts/build-test.sh +++ b/.ci/scripts/build-test.sh @@ -10,10 +10,9 @@ set -euxo pipefail # # Prepare junit build context -mkdir -p outputs -export OUT_FILE="outputs/test-report.out" +mkdir -p $(pwd)/outputs -make -C cli install test | tee ${OUT_FILE} +go get -v -u gotest.tools/gotestsum -go get -v -u github.com/jstemmer/go-junit-report -go-junit-report > outputs/TEST-unit.xml < ${OUT_FILE} +# See https://pkg.go.dev/gotest.tools/gotestsum/#readme-junit-xml-output +GOTESTSUM_JUNITFILE="$(pwd)/outputs/TEST-unit.xml" make -C cli install test diff --git a/.ci/scripts/install-dependencies.sh b/.ci/scripts/install-dependencies.sh index b953966dda..872ad9f725 100755 --- a/.ci/scripts/install-dependencies.sh +++ b/.ci/scripts/install-dependencies.sh @@ -10,10 +10,9 @@ set -euxo pipefail # # Install some other dependencies required for the pre-commit +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.34.1 + go get -v golang.org/x/lint/golint -go get -v github.com/go-lintpack/lintpack/... -go get -v github.com/go-critic/go-critic/... -lintpack build -o bin/gocritic -linter.version='v0.3.4' -linter.name='gocritic' github.com/go-critic/go-critic/checkers # Install project dependencies make -C cli install diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e3ea71ecf..04b04d9e80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,9 +21,9 @@ repos: hooks: - id: go-fmt - id: go-lint - - id: validate-toml + - id: go-vet - id: no-go-testing - - id: go-critic + - id: golangci-lint - repo: git@github.com:elastic/apm-pipeline-library rev: current diff --git a/cli/Makefile b/cli/Makefile index 7cde861469..d74fd7f793 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -37,4 +37,4 @@ notice: .PHONY: test test: - go test -v -timeout=$(TEST_TIMEOUT) ./... + gotestsum --format testname -- -count=1 -timeout=$(TEST_TIMEOUT) ./... diff --git a/cli/internal/state.go b/cli/internal/state.go index d1217394d2..41ae584595 100644 --- a/cli/internal/state.go +++ b/cli/internal/state.go @@ -90,17 +90,13 @@ func Update(id string, workdir string, composeFilePaths []string, env map[string } } - args := []string{} for i, f := range composeFilePaths { - args = append(args, "-f", f) - if i > 0 { run.Services = append(run.Services, stateService{ Name: filepath.Base(filepath.Dir(f)), }) } } - args = append(args, "config") bytes, err := yaml.Marshal(&run) if err != nil { diff --git a/e2e/runner_test.go b/e2e/runner_test.go deleted file mode 100644 index af3c4e2c92..0000000000 --- a/e2e/runner_test.go +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one -// or more contributor license agreements. Licensed under the Elastic License; -// you may not use this file except in compliance with the Elastic License. - -package e2e - -import ( - "flag" - "os" - "path" - "testing" - - "github.com/cucumber/godog" - "github.com/cucumber/godog/colors" - log "github.com/sirupsen/logrus" - - "github.com/elastic/e2e-testing/cli/config" -) - -type contextMetadata struct { - name string - modules []string - contextFuncs []func(s *godog.Suite) // the functions that hold the steps for a specific -} - -func (c *contextMetadata) getFeaturePaths() []string { - paths := []string{} - for _, module := range c.modules { - paths = append(paths, path.Join("features", module, c.name+".feature")) - } - - return paths -} - -var supportedProducts = map[string]*contextMetadata{} - -var opt = godog.Options{Output: colors.Colored(os.Stdout)} - -func init() { - config.Init() - - godog.BindFlags("godog.", flag.CommandLine, &opt) -} - -func TestMain(m *testing.M) { - flag.Parse() - - featurePaths, metadatas := parseFeatureFlags(flag.Args()) - - if len(metadatas) == 0 { - log.Error("We did not find anything to execute. Exiting") - os.Exit(1) - } - - opt.Paths = featurePaths - - status := godog.RunWithOptions("godog", func(s *godog.Suite) { - for _, metadata := range metadatas { - for _, f := range metadata.contextFuncs { - f(s) - } - } - }, opt) - - if st := m.Run(); st > status { - status = st - } - os.Exit(status) -} - -func findSupportedContext(feature string) *contextMetadata { - for k, ctx := range supportedProducts { - ctx.name = k // match key with context name - if k == feature { - log.WithFields(log.Fields{ - "paths": ctx.getFeaturePaths(), - "modules": ctx.modules, - }).Info("Feature Context found") - return ctx - } - } - - return nil -} - -func parseFeatureFlags(flags []string) ([]string, []*contextMetadata) { - metadatas := []*contextMetadata{} - featurePaths := []string{} - - if len(flags) == 1 && flags[0] == "" { - for k, metadata := range supportedProducts { - metadata.name = k // match key with context name - metadatas = append(metadatas, metadata) - } - } else { - for _, feature := range flags { - metadata := findSupportedContext(feature) - - if metadata == nil { - log.Warnf("Sorry but we don't support tests for %s at this moment. Skipping it :(", feature) - continue - } - - metadatas = append(metadatas, metadata) - featurePaths = append(featurePaths, metadata.getFeaturePaths()...) - } - } - - return featurePaths, metadatas -} diff --git a/e2e/utils.go b/e2e/utils.go index 252792df13..23b758fad9 100644 --- a/e2e/utils.go +++ b/e2e/utils.go @@ -28,8 +28,7 @@ import ( const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" //nolint:unused -var seededRand *rand.Rand = rand.New( - rand.NewSource(time.Now().UnixNano())) +var seededRand = rand.New(rand.NewSource(time.Now().UnixNano())) // GetExponentialBackOff returns a preconfigured exponential backoff instance func GetExponentialBackOff(elapsedTime time.Duration) *backoff.ExponentialBackOff {