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

chore(linters): Enable usetesting linter #16456

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

zak-pawel
Copy link
Collaborator

Summary

In this PR, I'm enabling usetesting linter and addressing following findings:

config/config_test.go:1106:15                                    usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestPersisterInputStoreLoad
logger/structured_logger_test.go:30:18                           usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredFile
logger/structured_logger_test.go:62:18                           usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredFileDebug
logger/structured_logger_test.go:94:18                           usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredFileError
logger/structured_logger_test.go:128:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredAddDefaultLogLevel
logger/structured_logger_test.go:162:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredDerivedLogger
logger/structured_logger_test.go:199:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredDerivedLoggerWithAttributes
logger/structured_logger_test.go:239:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredWriteToTruncatedFile
logger/structured_logger_test.go:313:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredLogMessageKey
logger/text_logger_test.go:28:18                                 usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextFile
logger/text_logger_test.go:49:18                                 usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextFileDebug
logger/text_logger_test.go:70:18                                 usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextFileError
logger/text_logger_test.go:92:18                                 usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextAddDefaultLogLevel
logger/text_logger_test.go:113:18                                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextWriteToTruncatedFile
logger/text_logger_test.go:165:18                                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextWriteDerivedLogger
logger/text_logger_test.go:189:18                                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTextWriteDerivedLoggerWithAttributes
plugins/inputs/bcache/bcache_test.go:27:17                       usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestBcacheGeneratesMetrics
plugins/inputs/conntrack/conntrack_test.go:39:17                 usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestDefaultsUsed
plugins/inputs/conntrack/conntrack_test.go:64:17                 usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestConfigsUsed
plugins/inputs/dpdk/dpdk_test.go:855:18                          usetesting  os.MkdirTemp() could be replaced by t.TempDir() in createSocketForTest
plugins/inputs/http_listener_v2/http_listener_v2_test.go:739:15  usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestUnixSocket
plugins/inputs/intel_baseband/intel_baseband_test.go:132:18      usetesting  os.MkdirTemp() could be replaced by t.TempDir() in newTempSocket
plugins/inputs/intel_baseband/intel_baseband_test.go:163:15      usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in newTempLogFile
plugins/inputs/intel_dlb/intel_dlb_test.go:882:18                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in Test_rasReader
plugins/inputs/kernel_vmstat/kernel_vmstat_test.go:301:18        usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in makeFakeVMStatFile
plugins/inputs/logparser/logparser_test.go:121:19                usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestGrokParseLogFilesAppearLater
plugins/inputs/lustre2/lustre2_test.go:175:17                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesHealth
plugins/inputs/lustre2/lustre2_test.go:205:17                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesMetrics
plugins/inputs/lustre2/lustre2_test.go:276:17                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesClientMetrics
plugins/inputs/lustre2/lustre2_test.go:341:17                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesJobstatsMetrics
plugins/inputs/lustre2/lustre2_test.go:502:17                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesBrwstatsMetrics
plugins/inputs/lustre2/lustre2_test.go:577:18                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestLustre2GeneratesEvictionMetrics
plugins/inputs/socket_listener/socket_listener_test.go:133:18    usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestSocketListener
plugins/inputs/socket_listener/socket_listener_test.go:280:15    usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestLargeReadBufferUnixgram
plugins/inputs/tail/tail_test.go:197:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGrokParseLogFilesWithMultilineTimeout
plugins/inputs/tail/tail_test.go:608:18                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTailEOF
plugins/inputs/tail/tail_test.go:648:16                          usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestCSVBehavior
plugins/inputs/x509_cert/x509_cert_test.go:42:18                 usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGatherRemoteIntegration
plugins/inputs/x509_cert/x509_cert_test.go:167:14                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGatherLocal
plugins/inputs/x509_cert/x509_cert_test.go:200:12                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestTags
plugins/inputs/x509_cert/x509_cert_test.go:249:12                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGatherExcludeRootCerts
plugins/inputs/x509_cert/x509_cert_test.go:286:14                usetesting  os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestGatherChain
plugins/inputs/x509_cert/x509_cert_test.go:490:17                usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestClassification
plugins/inputs/zfs/zfs_linux_test.go:223:17                      usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestZfsPoolMetrics
plugins/inputs/zfs/zfs_linux_test.go:282:17                      usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestZfsGeneratesMetrics
plugins/outputs/remotefile/remotefile_test.go:33:17              usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestStaticFileCreation
plugins/outputs/remotefile/remotefile_test.go:80:17              usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestStaticFileAppend
plugins/outputs/remotefile/remotefile_test.go:177:17             usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestDynamicFiles
plugins/outputs/remotefile/remotefile_test.go:245:17             usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestCustomTemplateFunctions
plugins/outputs/remotefile/remotefile_test.go:300:17             usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestCSVSerialization
plugins/outputs/remotefile/remotefile_test.go:360:17             usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestForgettingFiles
plugins/outputs/remotefile/remotefile_test.go:470:17             usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestTrackingMetrics
plugins/secretstores/jose/jose_test.go:60:18                     usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestSetListGet
plugins/secretstores/jose/jose_test.go:112:18                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestResolver
plugins/secretstores/jose/jose_test.go:140:18                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestResolverInvalid
plugins/secretstores/jose/jose_test.go:166:18                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestGetNonExistent
plugins/secretstores/jose/jose_test.go:189:18                    usetesting  os.MkdirTemp() could be replaced by t.TempDir() in TestGetInvalidPassword

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #16412

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zak-pawel! Just one suggestion...

Comment on lines 30 to 34
// t.TempDir() doesn't work properly on windows for this case
//nolint:usetesting // "os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredFile"
tmpfile, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
Copy link
Member

@srebhan srebhan Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm how about

Suggested change
// t.TempDir() doesn't work properly on windows for this case
//nolint:usetesting // "os.CreateTemp("", ...) could be replaced by os.CreateTemp(t.TempDir(), ...) in TestStructuredFile"
tmpfile, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
tmpfile := filepath.Join(t.TempDir(), "test.log")

of course including the changes for the parameters... Same for the instances below.

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Feb 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linter: usetesting - Should we enable it?
3 participants