Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: introduce additional linters for golangci-lint #463

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
philipp-hinteregger marked this conversation as resolved.
Show resolved Hide resolved
- 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
22 changes: 21 additions & 1 deletion operator/controllers/keptnappversion/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down