Skip to content

Add usetesting linter #6892

Open
Open
@yurishkuro

Description

@yurishkuro

There is some code clean that could be caught by adding a usetesting linter to .golangci.yml.

--- a/.golangci.yml
+++ b/.golangci.yml
@@ -108,6 +108,9 @@ linters:
     # Detects the possibility to use variables/constants from the Go standard library.
     - usestdlibvars

+    # Recommends using functions from `testing`
+    - usetesting
+

It will cause some linting failures like below that should be fixed as part of the same PR.

internal/jaegerclientenv2otel/envvars_test.go:16:2: os.Setenv() could be replaced by t.Setenv() in TestMapJaegerToOtelEnvVars (usetesting)
	os.Setenv("JAEGER_TAGS", "tags")
	^
internal/jaegerclientenv2otel/envvars_test.go:17:2: os.Setenv() could be replaced by t.Setenv() in TestMapJaegerToOtelEnvVars (usetesting)
	os.Setenv("JAEGER_USER", "user")
	^
internal/sampling/samplingstrategy/file/provider_test.go:352:17: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestAutoUpdateStrategyWithFile (usetesting)
	tempFile, _ := os.CreateTemp("", "for_go_test_*.json")
	               ^
internal/sampling/samplingstrategy/file/provider_test.go:439:17: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestAutoUpdateStrategyErrors (usetesting)
	tempFile, _ := os.CreateTemp("", "for_go_test_*.json")
	               ^
internal/storage/metricstore/prometheus/metricstore/reader_test.go:772:15: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGetRoundTripperTokenFile (usetesting)
	file, err := os.CreateTemp("", "token_")
	             ^
internal/storage/metricstore/prometheus/metricstore/reader_test.go:807:15: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGetRoundTripperTokenFromContext (usetesting)
	file, err := os.CreateTemp("", "token_")
	             ^
internal/storage/v1/elasticsearch/mappings/command_test.go:24:19: os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestCommandExecute (usetesting)
	tempFile, err := os.CreateTemp("", "command-output-*.txt")
	                 ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    goPull requests that update go codegood first issueGood for beginnershelp wantedFeatures that maintainers are willing to accept but do not have cycles to implement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions