Skip to content

Commit 05a457e

Browse files
authored
Refactor to use filepath.Join instead of path.Join (#2199)
1 parent cfd576f commit 05a457e

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

‎cmd/importer/util/util_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package util
1818

1919
import (
2020
"os"
21-
"path"
21+
"path/filepath"
2222
"testing"
2323

2424
"github.com/google/go-cmp/cmp"
@@ -76,7 +76,7 @@ var testMappingRules = MappingRules{
7676

7777
func TestMappingFromFile(t *testing.T) {
7878
tdir := t.TempDir()
79-
fPath := path.Join(tdir, "mapping.yaml")
79+
fPath := filepath.Join(tdir, "mapping.yaml")
8080
err := os.WriteFile(fPath, []byte(testContent), os.FileMode(0600))
8181
if err != nil {
8282
t.Fatalf("unable to create the test file: %s", err)

‎pkg/controller/admissionchecks/multikueue/fswatch_test.go‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"os"
23-
"path"
23+
"path/filepath"
2424
"runtime"
2525
"sync"
2626
"testing"
@@ -43,13 +43,13 @@ func TestFSWatch(t *testing.T) {
4343
"empty": {},
4444
"single cluster existing file": {
4545
prepareFnc: func(basePath string) error {
46-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
46+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
4747
},
4848
clusters: map[string]string{
4949
"c1": "c1.kubeconfig",
5050
},
5151
opFnc: func(basePath string) error {
52-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig"), []byte("123456"), 0666)
52+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig"), []byte("123456"), 0666)
5353
},
5454
wantEventsForClusters: set.New("c1"),
5555
},
@@ -58,55 +58,55 @@ func TestFSWatch(t *testing.T) {
5858
"c1": "c1.kubeconfig",
5959
},
6060
opFnc: func(basePath string) error {
61-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig"), []byte("123456"), 0666)
61+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig"), []byte("123456"), 0666)
6262
},
6363
wantEventsForClusters: set.New("c1"),
6464
},
6565
"single existing file deleted": {
6666
prepareFnc: func(basePath string) error {
67-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
67+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
6868
},
6969
clusters: map[string]string{
7070
"c1": "c1.kubeconfig",
7171
},
7272
opFnc: func(basePath string) error {
73-
return os.Remove(path.Join(basePath, "c1.kubeconfig"))
73+
return os.Remove(filepath.Join(basePath, "c1.kubeconfig"))
7474
},
7575
wantEventsForClusters: set.New("c1"),
7676
},
7777
"single cluster file rename to": {
7878
prepareFnc: func(basePath string) error {
79-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig.old"), []byte("123"), 0666)
79+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig.old"), []byte("123"), 0666)
8080
},
8181
clusters: map[string]string{
8282
"c1": "c1.kubeconfig",
8383
},
8484
opFnc: func(basePath string) error {
85-
return os.Rename(path.Join(basePath, "c1.kubeconfig.old"), path.Join(basePath, "c1.kubeconfig"))
85+
return os.Rename(filepath.Join(basePath, "c1.kubeconfig.old"), filepath.Join(basePath, "c1.kubeconfig"))
8686
},
8787
wantEventsForClusters: set.New("c1"),
8888
},
8989
"single cluster file rename from": {
9090
prepareFnc: func(basePath string) error {
91-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
91+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig"), []byte("123"), 0666)
9292
},
9393
clusters: map[string]string{
9494
"c1": "c1.kubeconfig",
9595
},
9696
opFnc: func(basePath string) error {
97-
return os.Rename(path.Join(basePath, "c1.kubeconfig"), path.Join(basePath, "c1.kubeconfig.new"))
97+
return os.Rename(filepath.Join(basePath, "c1.kubeconfig"), filepath.Join(basePath, "c1.kubeconfig.new"))
9898
},
9999
wantEventsForClusters: set.New("c1"),
100100
},
101101
"single create link": {
102102
prepareFnc: func(basePath string) error {
103-
return os.WriteFile(path.Join(basePath, "c1.kubeconfig.src"), []byte("123"), 0666)
103+
return os.WriteFile(filepath.Join(basePath, "c1.kubeconfig.src"), []byte("123"), 0666)
104104
},
105105
clusters: map[string]string{
106106
"c1": "c1.kubeconfig",
107107
},
108108
opFnc: func(basePath string) error {
109-
return os.Symlink(path.Join(basePath, "c1.kubeconfig.src"), path.Join(basePath, "c1.kubeconfig"))
109+
return os.Symlink(filepath.Join(basePath, "c1.kubeconfig.src"), filepath.Join(basePath, "c1.kubeconfig"))
110110
},
111111
wantEventsForClusters: set.New("c1"),
112112
},
@@ -116,16 +116,16 @@ func TestFSWatch(t *testing.T) {
116116
// fixed https://github.com/fsnotify/fsnotify/issues/636.
117117
skipOnDarwin: true,
118118
prepareFnc: func(basePath string) error {
119-
if err := os.WriteFile(path.Join(basePath, "c1.kubeconfig.src"), []byte("123"), 0666); err != nil {
119+
if err := os.WriteFile(filepath.Join(basePath, "c1.kubeconfig.src"), []byte("123"), 0666); err != nil {
120120
return err
121121
}
122-
return os.Symlink(path.Join(basePath, "c1.kubeconfig.src"), path.Join(basePath, "c1.kubeconfig"))
122+
return os.Symlink(filepath.Join(basePath, "c1.kubeconfig.src"), filepath.Join(basePath, "c1.kubeconfig"))
123123
},
124124
clusters: map[string]string{
125125
"c1": "c1.kubeconfig",
126126
},
127127
opFnc: func(basePath string) error {
128-
return os.Remove(path.Join(basePath, "c1.kubeconfig"))
128+
return os.Remove(filepath.Join(basePath, "c1.kubeconfig"))
129129
},
130130
wantEventsForClusters: set.New("c1"),
131131
},
@@ -168,7 +168,7 @@ func TestFSWatch(t *testing.T) {
168168

169169
gotAddErrors := map[string]error{}
170170
for c, p := range tc.clusters {
171-
if err := watcher.AddOrUpdate(c, path.Join(basePath, p)); err != nil {
171+
if err := watcher.AddOrUpdate(c, filepath.Join(basePath, p)); err != nil {
172172
gotAddErrors[c] = err
173173
}
174174
}
@@ -196,10 +196,10 @@ func TestFSWatchAddRm(t *testing.T) {
196196
ctx, cancel := context.WithCancel(context.Background())
197197
defer cancel()
198198
basePath := t.TempDir()
199-
f1Path := path.Join(basePath, "file.one")
200-
f2Path := path.Join(basePath, "file.two")
201-
f3Dir := path.Join(basePath, "d1")
202-
f3Path := path.Join(f3Dir, "file.three")
199+
f1Path := filepath.Join(basePath, "file.one")
200+
f2Path := filepath.Join(basePath, "file.two")
201+
f3Dir := filepath.Join(basePath, "d1")
202+
f3Path := filepath.Join(f3Dir, "file.three")
203203
steps := []struct {
204204
name string
205205
skipOnDarwin bool

‎test/integration/multikueue/multikueue_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package multikueue
1919
import (
2020
"fmt"
2121
"os"
22-
"path"
22+
"path/filepath"
2323
"time"
2424

2525
"github.com/google/go-cmp/cmp/cmpopts"
@@ -358,7 +358,7 @@ var _ = ginkgo.Describe("Multikueue", func() {
358358
})
359359

360360
tempDir := ginkgo.GinkgoT().TempDir()
361-
fsKubeConfig := path.Join(tempDir, "testing.kubeconfig")
361+
fsKubeConfig := filepath.Join(tempDir, "testing.kubeconfig")
362362

363363
config := utiltesting.MakeMultiKueueConfig("testing-config").Clusters("testing-cluster").Obj()
364364
ginkgo.By("creating the config, the admission check's state is updated", func() {

‎test/performance/scheduler/runner/generator/generator_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package generator
1818

1919
import (
2020
"os"
21-
"path"
21+
"path/filepath"
2222
"testing"
2323

2424
"github.com/google/go-cmp/cmp"
@@ -120,7 +120,7 @@ func TestLoadConfig(t *testing.T) {
120120
request: 20
121121
`
122122
tempDir := t.TempDir()
123-
fPath := path.Join(tempDir, "config.yaml")
123+
fPath := filepath.Join(tempDir, "config.yaml")
124124
err := os.WriteFile(fPath, []byte(testContent), os.FileMode(0600))
125125
if err != nil {
126126
t.Fatalf("unable to create the test file: %s", err)

‎test/performance/scheduler/runner/main.go‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"os/exec"
2525
"os/signal"
2626
"path"
27+
"path/filepath"
2728
"strconv"
2829
"sync"
2930
"syscall"
@@ -131,7 +132,7 @@ func main() {
131132
os.Exit(1)
132133
}
133134

134-
kubeconfigPath := path.Join(*outputDir, "kubeconfig")
135+
kubeconfigPath := filepath.Join(*outputDir, "kubeconfig")
135136
err = os.WriteFile(kubeconfigPath, kubeconfig, 00660)
136137
if err != nil {
137138
log.Error(err, "Write kubeconfig")
@@ -184,7 +185,7 @@ func main() {
184185
}
185186

186187
if *metricsScrapeInterval != 0 && *metricsScrapeURL != "" {
187-
dumpTar := path.Join(*outputDir, "metricsDump.tgz")
188+
dumpTar := filepath.Join(*outputDir, "metricsDump.tgz")
188189
err := runScraper(ctx, *metricsScrapeInterval, dumpTar, *metricsScrapeURL, errCh, wg)
189190
if err != nil {
190191
log.Error(err, "Scraper start")
@@ -217,17 +218,17 @@ func main() {
217218
os.Exit(1)
218219
}
219220

220-
err = recorder.WriteSummary(path.Join(*outputDir, "summary.yaml"))
221+
err = recorder.WriteSummary(filepath.Join(*outputDir, "summary.yaml"))
221222
if err != nil {
222223
log.Error(err, "Writing summary")
223224
os.Exit(1)
224225
}
225-
err = recorder.WriteCQCsv(path.Join(*outputDir, "cqStates.csv"))
226+
err = recorder.WriteCQCsv(filepath.Join(*outputDir, "cqStates.csv"))
226227
if err != nil {
227228
log.Error(err, "Writing cq csv")
228229
os.Exit(1)
229230
}
230-
err = recorder.WriteWLCsv(path.Join(*outputDir, "wlStates.csv"))
231+
err = recorder.WriteWLCsv(filepath.Join(*outputDir, "wlStates.csv"))
231232
if err != nil {
232233
log.Error(err, "Writing wl csv")
233234
os.Exit(1)
@@ -246,7 +247,7 @@ func main() {
246247
func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCPUProf, withLogs, logToFile bool, logLevel int, errCh chan<- error, wg *sync.WaitGroup, metricsPort int) error {
247248
log := ctrl.LoggerFrom(ctx).WithName("Run command")
248249

249-
cmd := exec.CommandContext(ctx, cmdPath, "--kubeconfig", path.Join(workDir, kubeconfig))
250+
cmd := exec.CommandContext(ctx, cmdPath, "--kubeconfig", filepath.Join(workDir, kubeconfig))
250251
cmd.Cancel = func() error {
251252
log.Info("Stop the command")
252253
return cmd.Process.Signal(syscall.SIGINT)
@@ -255,7 +256,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
255256
exe := path.Base(cmdPath)
256257

257258
if withCPUProf {
258-
cmd.Args = append(cmd.Args, "--cpuprofile", path.Join(workDir, fmt.Sprintf("%s.cpu.prof", exe)))
259+
cmd.Args = append(cmd.Args, "--cpuprofile", filepath.Join(workDir, fmt.Sprintf("%s.cpu.prof", exe)))
259260
}
260261

261262
if withLogs {
@@ -264,13 +265,13 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
264265
errWriter := os.Stderr
265266
if logToFile {
266267
var err error
267-
outWriter, err = os.Create(path.Join(workDir, fmt.Sprintf("%s.out.log", exe)))
268+
outWriter, err = os.Create(filepath.Join(workDir, fmt.Sprintf("%s.out.log", exe)))
268269
if err != nil {
269270
return err
270271
}
271272
defer outWriter.Close()
272273

273-
errWriter, err = os.Create(path.Join(workDir, fmt.Sprintf("%s.err.log", exe)))
274+
errWriter, err = os.Create(filepath.Join(workDir, fmt.Sprintf("%s.err.log", exe)))
274275
if err != nil {
275276
return err
276277
}
@@ -320,7 +321,7 @@ func runCommand(ctx context.Context, workDir, cmdPath, kubeconfig string, withCP
320321
return
321322
}
322323

323-
err = os.WriteFile(path.Join(workDir, fmt.Sprintf("%s.stats.yaml", exe)), csBytes, 0666)
324+
err = os.WriteFile(filepath.Join(workDir, fmt.Sprintf("%s.stats.yaml", exe)), csBytes, 0666)
324325
if err != nil {
325326
log.Error(err, "Writing cmd stats")
326327
}

0 commit comments

Comments
 (0)