From 600c6ac270c75e79042fef0277e37cc0a86c775b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 4 Jan 2021 17:03:21 +0100 Subject: [PATCH] fix: use golangci-lint in favour of go-critic (#550) * fix: remove var type as per golint's suggestion * chore: add golangci-lint precommit hook * chore: remove go-critic in fafvour of golangci-lint * chore: remove TOML hook * chore: add go-vet hook * fix: remove unused variable Detected by golangci-lint * fix: remove unused Go file, which caused lint errors --- .ci/scripts/install-dependencies.sh | 5 +- .pre-commit-config.yaml | 4 +- cli/internal/state.go | 4 - e2e/runner_test.go | 110 ---------------------------- e2e/utils.go | 3 +- 5 files changed, 5 insertions(+), 121 deletions(-) delete mode 100644 e2e/runner_test.go 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/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 aa6b257c31..984140879e 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 {