Skip to content

Commit aede3d1

Browse files
committed
switch tenv with usetesting
1 parent 4e2aad9 commit aede3d1

File tree

4 files changed

+7
-36
lines changed

4 files changed

+7
-36
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-16
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,18 @@ 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

437425
t.Cleanup(func() { os.RemoveAll(tmpRootDir) })
438-
err = Crosslink(test.config)
426+
err := Crosslink(test.config)
439427
assert.Error(t, err)
440428
err = Prune(test.config)
441429
assert.Error(t, err)
442430
})
443431
}
444-
445432
}
446433

447434
// Testing skipping specified go modules.
@@ -526,7 +513,6 @@ func TestSkip(t *testing.T) {
526513
}
527514
}
528515
modFileActual, err := os.ReadFile(filepath.Clean(modFilePath))
529-
530516
if err != nil {
531517
t.Fatalf("TestCase: %s, error reading actual mod files: %v", test.testCase, err)
532518
}

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-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ 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
}

0 commit comments

Comments
 (0)