From ec7f58e6e5ad5193b315b50d5c08b313ca951e4e Mon Sep 17 00:00:00 2001 From: Philipp Hinteregger Date: Wed, 23 Nov 2022 15:19:06 +0100 Subject: [PATCH 1/2] ci: introduce additional linters for golangci-lint Signed-off-by: Philipp Hinteregger --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 13 ++++++----- .../keptnappversion/controller_test.go | 22 ++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5f43fdd035..ca83895fb8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,7 +16,7 @@ jobs: - name: "scheduler" folder: "scheduler/" steps: - - name: Check out code into the Go module directory + - name: Check out code uses: actions/checkout@v3 - uses: actions/setup-go@v3 diff --git a/.golangci.yml b/.golangci.yml index b6648a3ad5..fe34b7da78 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,14 +5,17 @@ linters: enable: - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification - gci # Gci controls golang package import order and makes it always deterministic. -# - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. -# - containedctx # containedctx is a linter that detects struct contained context.Context field -# - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) -# - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. -# - noctx # noctx finds sending http request without context.Context + - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - containedctx # containedctx is a linter that detects struct contained context.Context field + - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) + - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. + - noctx # noctx finds sending http request without context.Context issues: exclude-rules: - linters: - gci text: '//+kubebuilder' + - linters: + - containedctx + path: _test\.go diff --git a/operator/controllers/keptnappversion/controller_test.go b/operator/controllers/keptnappversion/controller_test.go index 2ce9e19007..c0577c8e7c 100644 --- a/operator/controllers/keptnappversion/controller_test.go +++ b/operator/controllers/keptnappversion/controller_test.go @@ -136,6 +136,26 @@ func createFinishedAppVersionStatus() lfcv1alpha1.KeptnAppVersionStatus { } } +func setupReconcilerWithMeters(t *testing.T) *KeptnAppVersionReconciler { + //setup logger + opts := zap.Options{ + Development: true, + } + ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) + + //fake a tracer + tr := &fake.ITracerMock{StartFunc: func(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { + return ctx, trace.SpanFromContext(ctx) + }} + + r := &KeptnAppVersionReconciler{ + Log: ctrl.Log.WithName("test-appVersionController"), + Tracer: tr, + Meters: utils.InitAppMeters(), + } + return r +} + func setupReconciler(t *testing.T) (*KeptnAppVersionReconciler, chan string, *fake.ITracerMock, *fake.SpanHandlerIMock) { //setup logger opts := zap.Options{ @@ -176,7 +196,7 @@ func setupReconciler(t *testing.T) (*KeptnAppVersionReconciler, chan string, *fa func TestKeptnApVersionReconciler_setupSpansContexts(t *testing.T) { - r, _, _, _ := setupReconciler(t) + r := setupReconcilerWithMeters(t) type args struct { ctx context.Context appVersion *lfcv1alpha1.KeptnAppVersion From bc5449ada5754e5284c1ad467d89f825d1fe37c9 Mon Sep 17 00:00:00 2001 From: Philipp Hinteregger Date: Thu, 24 Nov 2022 11:43:29 +0100 Subject: [PATCH 2/2] Update .golangci.yml Co-authored-by: Moritz Wiesinger Signed-off-by: Philipp Hinteregger --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index fe34b7da78..17f107a0a8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,7 @@ linters: enable: - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification - gci # Gci controls golang package import order and makes it always deterministic. - - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + - errorlint # errorlint is a linter that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - containedctx # containedctx is a linter that detects struct contained context.Context field - dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f()) - nilnil # Checks that there is no simultaneous return of nil error and an invalid value.