Skip to content

Commit 379a7d2

Browse files
dmathieumx-psi
andauthoredMar 10, 2025··
switch tenv with usetesting (#718)
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
1 parent 397d304 commit 379a7d2

File tree

4 files changed

+7
-38
lines changed

4 files changed

+7
-38
lines changed
 

‎.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ linters:
131131
- misspell
132132
- revive
133133
- staticcheck
134-
- tenv
135134
- unconvert
136135
- unused
137136
- unparam
137+
- usetesting
138138

139139
issues:
140140
# Excluding configuration per-path, per-linter, per-text and per-source

‎crosslink/internal/crosslink_test.go

+2-17
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ func TestCrosslink(t *testing.T) {
134134
err = Crosslink(test.config)
135135

136136
if assert.NoError(t, err, "error message on execution %s") {
137-
138137
for modFilePath, modFilesExpected := range test.expected {
139138
modFileActual, err := os.ReadFile(filepath.Clean(filepath.Join(tmpRootDir, modFilePath)))
140-
141139
if err != nil {
142140
t.Fatalf("error reading actual mod files: %v", err)
143141
}
@@ -167,7 +165,6 @@ func TestCrosslink(t *testing.T) {
167165
}
168166
}
169167
}
170-
171168
})
172169
}
173170
}
@@ -256,7 +253,6 @@ func TestOverwrite(t *testing.T) {
256253

257254
for modFilePath, modFilesExpected := range test.expected {
258255
modFileActual, err := os.ReadFile(filepath.Clean(filepath.Join(tmpRootDir, modFilePath)))
259-
260256
if err != nil {
261257
t.Fatalf("error reading actual mod files: %v", err)
262258
}
@@ -286,14 +282,12 @@ func TestOverwrite(t *testing.T) {
286282
}
287283
}
288284
}
289-
290285
})
291286
}
292287
err := lg.Sync()
293288
if err != nil {
294289
fmt.Printf("failed to sync logger: %v", err)
295290
}
296-
297291
}
298292

299293
// Testing exclude functionality for prune, overwrite, and no overwrite.
@@ -372,7 +366,6 @@ func TestExclude(t *testing.T) {
372366

373367
for modFilePath, modFilesExpected := range modFilesExpected {
374368
modFileActual, err := os.ReadFile(filepath.Clean(modFilePath))
375-
376369
if err != nil {
377370
t.Fatalf("TestCase: %s, error reading actual mod files: %v", test.testCase, err)
378371
}
@@ -410,13 +403,11 @@ func TestBadRootPath(t *testing.T) {
410403
lg, _ := zap.NewDevelopment()
411404
tests := []struct {
412405
testName string
413-
mockDir string
414406
setConfigPath bool
415407
config RunConfig
416408
}{
417409
{
418410
testName: "noGoMod",
419-
mockDir: "noGoMod",
420411
setConfigPath: true,
421412
config: RunConfig{
422413
Logger: lg,
@@ -426,22 +417,17 @@ func TestBadRootPath(t *testing.T) {
426417

427418
for _, test := range tests {
428419
t.Run(test.testName, func(t *testing.T) {
429-
tmpRootDir, err := os.MkdirTemp(testDataDir, test.mockDir)
430-
if err != nil {
431-
t.Fatalf("Failed to create temp dir %v", err)
432-
}
420+
tmpRootDir := t.TempDir()
433421
if test.setConfigPath {
434422
test.config.RootPath = tmpRootDir
435423
}
436424

437-
t.Cleanup(func() { os.RemoveAll(tmpRootDir) })
438-
err = Crosslink(test.config)
425+
err := Crosslink(test.config)
439426
assert.Error(t, err)
440427
err = Prune(test.config)
441428
assert.Error(t, err)
442429
})
443430
}
444-
445431
}
446432

447433
// Testing skipping specified go modules.
@@ -526,7 +512,6 @@ func TestSkip(t *testing.T) {
526512
}
527513
}
528514
modFileActual, err := os.ReadFile(filepath.Clean(modFilePath))
529-
530515
if err != nil {
531516
t.Fatalf("TestCase: %s, error reading actual mod files: %v", test.testCase, err)
532517
}

‎multimod/internal/sync/sync_test.go

+3-18
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ func TestNewSync(t *testing.T) {
4545
myVersioningFilename := filepath.Join(versionsYamlDir, "versions_valid.yaml")
4646
otherVersioningFilename := filepath.Join(versionsYamlDir, "other_versions_valid.yaml")
4747

48-
tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
49-
if err != nil {
50-
t.Fatal("creating temp dir:", err)
51-
}
52-
53-
defer os.RemoveAll(tmpRootDir)
48+
tmpRootDir := t.TempDir()
5449

5550
modFiles := map[string][]byte{
5651
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +
@@ -273,12 +268,7 @@ func TestUpdateAllGoModFilesWithCommitHash(t *testing.T) {
273268
}
274269

275270
for _, tc := range testCases {
276-
tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
277-
if err != nil {
278-
t.Fatal("creating temp dir:", err)
279-
}
280-
281-
defer os.RemoveAll(tmpRootDir)
271+
tmpRootDir := t.TempDir()
282272

283273
modFiles := map[string][]byte{
284274
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +
@@ -475,12 +465,7 @@ func TestUpdateAllGoModFiles(t *testing.T) {
475465
}
476466

477467
for _, tc := range testCases {
478-
tmpRootDir, err := os.MkdirTemp(testDataDir, testName)
479-
if err != nil {
480-
t.Fatal("creating temp dir:", err)
481-
}
482-
483-
defer os.RemoveAll(tmpRootDir)
468+
tmpRootDir := t.TempDir()
484469

485470
modFiles := map[string][]byte{
486471
filepath.Join(tmpRootDir, "my", "test", "test1", "go.mod"): []byte("module go.opentelemetry.io/build-tools/multimod/internal/sync/test/test1\n\n" +

‎semconvgen/generator_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ func TestCapitalizations(t *testing.T) {
5757

5858
for _, tt := range tests {
5959
t.Run(tt.name, func(t *testing.T) {
60-
tmpfile, err := os.CreateTemp("", "test")
60+
tmpfile, err := os.CreateTemp(t.TempDir(), "test")
6161
if err != nil {
6262
t.Fatal(err)
6363
}
64-
defer os.Remove(tmpfile.Name())
6564

6665
if _, err = tmpfile.Write([]byte(tt.capitalizations)); err != nil {
6766
t.Fatal(err)

0 commit comments

Comments
 (0)
Please sign in to comment.