Repository: jaegertracing/jaeger

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

```diff
--- 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")
	                 ^
```


Hints from issue comments:
@anurag-rajawat: Hi @yurishkuro, can I pick this up?@yurishkuro: yes

Solution patch:
diff --git a/.golangci.yml b/.golangci.yml
index 47fb0ceb..4f2a33de 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -24,6 +24,7 @@ linters:
     - revive
     - testifylint
     - usestdlibvars
+    - usetesting
   disable:
     - errcheck
     - staticcheck



Test patch:
diff --git a/internal/fswatcher/fswatcher_test.go b/internal/fswatcher/fswatcher_test.go
index 0599055f..c183cecc 100644
--- a/internal/fswatcher/fswatcher_test.go
+++ b/internal/fswatcher/fswatcher_test.go
@@ -76,11 +76,12 @@ func TestFSWatcherAddFiles(t *testing.T) {
 }
 
 func TestFSWatcherWithMultipleFiles(t *testing.T) {
-	testFile1, err := os.CreateTemp("", "")
+	tempDir := t.TempDir()
+	testFile1, err := os.Create(tempDir + "test-file-1")
 	require.NoError(t, err)
 	defer testFile1.Close()
 
-	testFile2, err := os.CreateTemp("", "")
+	testFile2, err := os.Create(tempDir + "test-file-2")
 	require.NoError(t, err)
 	defer testFile2.Close()
 
diff --git a/internal/jaegerclientenv2otel/envvars_test.go b/internal/jaegerclientenv2otel/envvars_test.go
index e4e095b5..90c2b4bc 100644
--- a/internal/jaegerclientenv2otel/envvars_test.go
+++ b/internal/jaegerclientenv2otel/envvars_test.go
@@ -13,9 +13,8 @@ import (
 )
 
 func TestMapJaegerToOtelEnvVars(t *testing.T) {
-	os.Setenv("JAEGER_TAGS", "tags")
-	os.Setenv("JAEGER_USER", "user")
-	os.Unsetenv("OTEL_EXPORTER_JAEGER_USER")
+	t.Setenv("JAEGER_TAGS", "tags")
+	t.Setenv("JAEGER_USER", "user")
 
 	logger, buffer := testutils.NewLogger()
 	MapJaegerToOtelEnvVars(logger)
diff --git a/internal/sampling/samplingstrategy/file/provider_test.go b/internal/sampling/samplingstrategy/file/provider_test.go
index 23a8fc85..b1b1779e 100644
--- a/internal/sampling/samplingstrategy/file/provider_test.go
+++ b/internal/sampling/samplingstrategy/file/provider_test.go
@@ -347,11 +347,8 @@ func TestDeepCopy(t *testing.T) {
 }
 
 func TestAutoUpdateStrategyWithFile(t *testing.T) {
-	tempFile, _ := os.CreateTemp("", "for_go_test_*.json")
+	tempFile, _ := os.Create(t.TempDir() + "for_go_test_*.json")
 	require.NoError(t, tempFile.Close())
-	defer func() {
-		require.NoError(t, os.Remove(tempFile.Name()))
-	}()
 
 	// copy known fixture content into temp file which we can later overwrite
 	srcFile, dstFile := "fixtures/strategies.json", tempFile.Name()
@@ -434,11 +431,8 @@ func TestAutoUpdateStrategyWithURL(t *testing.T) {
 }
 
 func TestAutoUpdateStrategyErrors(t *testing.T) {
-	tempFile, _ := os.CreateTemp("", "for_go_test_*.json")
+	tempFile, _ := os.Create(t.TempDir() + "for_go_test_*.json")
 	require.NoError(t, tempFile.Close())
-	defer func() {
-		_ = os.Remove(tempFile.Name())
-	}()
 
 	zapCore, logs := observer.New(zap.InfoLevel)
 	logger := zap.New(zapCore)
diff --git a/internal/storage/metricstore/prometheus/metricstore/reader_test.go b/internal/storage/metricstore/prometheus/metricstore/reader_test.go
index d1d7c4ca..6172aa74 100644
--- a/internal/storage/metricstore/prometheus/metricstore/reader_test.go
+++ b/internal/storage/metricstore/prometheus/metricstore/reader_test.go
@@ -769,9 +769,8 @@ func TestGetRoundTripperTLSConfig(t *testing.T) {
 func TestGetRoundTripperTokenFile(t *testing.T) {
 	const wantBearer = "token from file"
 
-	file, err := os.CreateTemp("", "token_")
+	file, err := os.Create(t.TempDir() + "token_")
 	require.NoError(t, err)
-	defer func() { require.NoError(t, os.Remove(file.Name())) }()
 
 	_, err = file.Write([]byte(wantBearer))
 	require.NoError(t, err)
@@ -804,9 +803,9 @@ func TestGetRoundTripperTokenFile(t *testing.T) {
 }
 
 func TestGetRoundTripperTokenFromContext(t *testing.T) {
-	file, err := os.CreateTemp("", "token_")
+	file, err := os.Create(t.TempDir() + "token_")
 	require.NoError(t, err)
-	defer func() { require.NoError(t, os.Remove(file.Name())) }()
+
 	_, err = file.Write([]byte("token from file"))
 	require.NoError(t, err)
 	require.NoError(t, file.Close())
diff --git a/internal/storage/v1/elasticsearch/mappings/command_test.go b/internal/storage/v1/elasticsearch/mappings/command_test.go
index 87109b6c..970e6073 100644
--- a/internal/storage/v1/elasticsearch/mappings/command_test.go
+++ b/internal/storage/v1/elasticsearch/mappings/command_test.go
@@ -21,9 +21,8 @@ func TestCommandExecute(t *testing.T) {
 	cmd := Command()
 
 	// TempFile to capture output
-	tempFile, err := os.CreateTemp("", "command-output-*.txt")
+	tempFile, err := os.Create(t.TempDir() + "command-output-*.txt")
 	require.NoError(t, err)
-	defer os.Remove(tempFile.Name())
 
 	// Redirect stdout to the TempFile
 	oldStdout := os.Stdout