mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
lint: enable usetesting linter (#7322)
Enable the usetesting linter in golangci.yml configuration to enforce proper testing practices. Replace manual temporary directory and file creation with t.TempDir() in test files. This improves test reliability by ensuring proper cleanup and follows Go testing best practices. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
@@ -8,6 +8,7 @@ linters:
|
|||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
|
- usetesting
|
||||||
exclusions:
|
exclusions:
|
||||||
generated: lax
|
generated: lax
|
||||||
presets:
|
presets:
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func TestPrint(t *testing.T) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
f, err := os.CreateTemp("", "print_test_tmp")
|
f, err := os.CreateTemp(t.TempDir(), "print_test_tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -79,15 +78,8 @@ func TestNewTLSConfigFromArgs(t *testing.T) {
|
|||||||
|
|
||||||
func TestNewTLSConfigFromArgsWithRoot(t *testing.T) {
|
func TestNewTLSConfigFromArgsWithRoot(t *testing.T) {
|
||||||
cert, key, ca := getPEMFiles(t)
|
cert, key, ca := getPEMFiles(t)
|
||||||
tempDir, err := os.MkdirTemp("", "go-test-pemfiles")
|
tempDir := t.TempDir()
|
||||||
defer func() {
|
|
||||||
if err := os.RemoveAll(tempDir); err != nil {
|
|
||||||
t.Error("failed to clean up temporary directory", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
t.Error("failed to create temporary directory", err)
|
|
||||||
}
|
|
||||||
root := tempDir
|
root := tempDir
|
||||||
args := []string{cert, key, ca}
|
args := []string{cert, key, ca}
|
||||||
for i := range args {
|
for i := range args {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestRoot(t *testing.T) {
|
|||||||
|
|
||||||
nonExistingDir := filepath.Join(existingDirPath, "highly_unlikely_to_exist_dir")
|
nonExistingDir := filepath.Join(existingDirPath, "highly_unlikely_to_exist_dir")
|
||||||
|
|
||||||
existingFile, err := os.CreateTemp("", "root_test")
|
existingFile, err := os.CreateTemp(t.TempDir(), "root_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("BeforeTest: Failed to create temp file for testing! Error was: %v", err)
|
t.Fatalf("BeforeTest: Failed to create temp file for testing! Error was: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user