|
4 | 4 | "context"
|
5 | 5 | "encoding/json"
|
6 | 6 | "fmt"
|
7 |
| - "io/ioutil" |
8 | 7 | "os"
|
9 | 8 | "path/filepath"
|
10 | 9 | "regexp"
|
@@ -297,7 +296,7 @@ func validateMounts(t *testing.T, dir string, tst testCase, rsp *v1alpha1.MountR
|
297 | 296 |
|
298 | 297 | // Check for the expected secrets
|
299 | 298 | for file, val := range tst.expSecrets {
|
300 |
| - secretVal, err := ioutil.ReadFile(filepath.Join(dir, file)) |
| 299 | + secretVal, err := os.ReadFile(filepath.Join(dir, file)) |
301 | 300 | if err != nil {
|
302 | 301 | t.Errorf("%s: Can not read file %s", tst.testName, file)
|
303 | 302 | return false
|
@@ -349,7 +348,7 @@ func validateResponse(t *testing.T, dir string, tst testCase, rsp *v1alpha1.Moun
|
349 | 348 | t.Errorf("%s: could not create base directory: %v", tst.testName, err)
|
350 | 349 | return false
|
351 | 350 | }
|
352 |
| - if err := ioutil.WriteFile(fullPath, secretVal, os.FileMode(perm)); err != nil { |
| 351 | + if err := os.WriteFile(fullPath, secretVal, os.FileMode(perm)); err != nil { |
353 | 352 | t.Errorf("%s: could not write secret: %v", tst.testName, err)
|
354 | 353 | return false
|
355 | 354 | }
|
@@ -1994,11 +1993,7 @@ func TestMounts(t *testing.T) {
|
1994 | 1993 |
|
1995 | 1994 | t.Run(tst.testName, func(t *testing.T) {
|
1996 | 1995 |
|
1997 |
| - dir, err := ioutil.TempDir("", strings.Map(nameMapper, tst.testName)) |
1998 |
| - if err != nil { |
1999 |
| - panic(err) |
2000 |
| - } |
2001 |
| - defer os.RemoveAll(dir) // Cleanup |
| 1996 | + dir := t.TempDir() // t.TempDir() handles cleanup automatically |
2002 | 1997 |
|
2003 | 1998 | svr := newServerWithMocks(&tst, false)
|
2004 | 1999 |
|
@@ -2035,11 +2030,7 @@ func TestMountsNoWrite(t *testing.T) {
|
2035 | 2030 |
|
2036 | 2031 | t.Run(tst.testName, func(t *testing.T) {
|
2037 | 2032 |
|
2038 |
| - dir, err := ioutil.TempDir("", strings.Map(nameMapper, tst.testName)) |
2039 |
| - if err != nil { |
2040 |
| - panic(err) |
2041 |
| - } |
2042 |
| - defer os.RemoveAll(dir) // Cleanup |
| 2033 | + dir := t.TempDir() // t.TempDir() handles cleanup automatically |
2043 | 2034 |
|
2044 | 2035 | svr := newServerWithMocks(&tst, true)
|
2045 | 2036 |
|
@@ -2452,11 +2443,7 @@ var remountTests []testCase = []testCase{
|
2452 | 2443 | // Validate rotation
|
2453 | 2444 | func TestReMounts(t *testing.T) {
|
2454 | 2445 |
|
2455 |
| - dir, err := ioutil.TempDir("", "TestReMounts") |
2456 |
| - if err != nil { |
2457 |
| - panic(err) |
2458 |
| - } |
2459 |
| - defer os.RemoveAll(dir) // Cleanup |
| 2446 | + dir := t.TempDir() // t.TempDir() handles cleanup automatically |
2460 | 2447 |
|
2461 | 2448 | curState := []*v1alpha1.ObjectVersion{}
|
2462 | 2449 |
|
@@ -2494,11 +2481,7 @@ func TestReMounts(t *testing.T) {
|
2494 | 2481 | // Validate rotation
|
2495 | 2482 | func TestNoWriteReMounts(t *testing.T) {
|
2496 | 2483 |
|
2497 |
| - dir, err := ioutil.TempDir("", "TestReMounts") |
2498 |
| - if err != nil { |
2499 |
| - panic(err) |
2500 |
| - } |
2501 |
| - defer os.RemoveAll(dir) // Cleanup |
| 2484 | + dir := t.TempDir() // t.TempDir() handles cleanup automatically |
2502 | 2485 |
|
2503 | 2486 | curState := []*v1alpha1.ObjectVersion{}
|
2504 | 2487 |
|
|
0 commit comments