Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit 8a2c63d

Browse files
committed
refactor(filepath): Use path/filepath pkg
1 parent 9083d82 commit 8a2c63d

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

cmd/sqlfmt/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"io"
77
"io/ioutil"
88
"os"
9-
"path"
109
"path/filepath"
1110

1211
"github.com/jackc/sqlfmt"
@@ -57,7 +56,7 @@ func (j *job) run() error {
5756
if j.w == nil {
5857
dir := filepath.Dir(j.name)
5958
base := filepath.Base(j.name)
60-
tmpPath = path.Join(dir, "."+base+".sqlfmt")
59+
tmpPath = filepath.Join(dir, "."+base+".sqlfmt")
6160
j.w, err = os.Create(tmpPath)
6261
if err != nil {
6362
return err

cmd/sqlfmt/sqlfmt_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"io/ioutil"
77
"os"
88
"os/exec"
9-
"path"
9+
"path/filepath"
1010
"runtime"
1111
"testing"
1212
)
@@ -78,19 +78,19 @@ func TestFileInput(t *testing.T) {
7878
inputFile := "simple_select_without_from.input.sql"
7979
expectedOutputFile := "simple_select_without_from.golden.sql"
8080

81-
expected, err := ioutil.ReadFile(path.Join("../../testdata", expectedOutputFile))
81+
expected, err := ioutil.ReadFile(filepath.Join("../../testdata", expectedOutputFile))
8282
if err != nil {
8383
t.Fatal(err)
8484
}
8585

86-
filePath := path.Join("../../testdata", inputFile)
86+
filePath := filepath.Join("../../testdata", inputFile)
8787
output, err := sqlfmt(nil, filePath)
8888
if err != nil {
8989
t.Fatalf("sqlfmt failed with %s: %v", filePath, err)
9090
}
9191

9292
if bytes.Compare(output, expected) != 0 {
93-
actualFileName := path.Join("tmp", "TestFileInput.sql")
93+
actualFileName := filepath.Join("tmp", "TestFileInput.sql")
9494
err = ioutil.WriteFile(actualFileName, output, os.ModePerm)
9595
if err != nil {
9696
t.Fatal(err)
@@ -103,20 +103,20 @@ func TestFileInput(t *testing.T) {
103103
func TestFileFormatInPlace(t *testing.T) {
104104
inputFile := "simple_select_without_from.input.sql"
105105
expectedOutputFile := "simple_select_without_from.golden.sql"
106-
expectedOutputPath := path.Join("../../testdata", expectedOutputFile)
106+
expectedOutputPath := filepath.Join("../../testdata", expectedOutputFile)
107107

108108
expected, err := ioutil.ReadFile(expectedOutputPath)
109109
if err != nil {
110110
t.Fatal(err)
111111
}
112112

113-
sourcePath := path.Join("../../testdata", inputFile)
113+
sourcePath := filepath.Join("../../testdata", inputFile)
114114
source, err := ioutil.ReadFile(sourcePath)
115115
if err != nil {
116116
t.Fatal(err)
117117
}
118118

119-
tmpFilePath := path.Join("tmp", inputFile)
119+
tmpFilePath := filepath.Join("tmp", inputFile)
120120
err = ioutil.WriteFile(tmpFilePath, source, os.ModePerm)
121121
if err != nil {
122122
t.Fatal(err)
@@ -155,19 +155,19 @@ func TestMultipleFileFormatInPlace(t *testing.T) {
155155
var err error
156156
args := []string{"-w"}
157157
for i, _ := range tests {
158-
sourcePath := path.Join("../../testdata", tests[i].Name+".input.sql")
158+
sourcePath := filepath.Join("../../testdata", tests[i].Name+".input.sql")
159159
tests[i].Source, err = ioutil.ReadFile(sourcePath)
160160
if err != nil {
161161
t.Fatal(err)
162162
}
163163

164-
expectedOutputPath := path.Join("../../testdata", tests[i].Name+".golden.sql")
164+
expectedOutputPath := filepath.Join("../../testdata", tests[i].Name+".golden.sql")
165165
tests[i].Expected, err = ioutil.ReadFile(expectedOutputPath)
166166
if err != nil {
167167
t.Fatal(err)
168168
}
169169

170-
tests[i].TmpFilePath = path.Join("tmp", tests[i].Name+".sql")
170+
tests[i].TmpFilePath = filepath.Join("tmp", tests[i].Name+".sql")
171171
err = ioutil.WriteFile(tests[i].TmpFilePath, tests[i].Source, os.ModePerm)
172172
if err != nil {
173173
t.Fatal(err)
@@ -209,8 +209,8 @@ func TestSqlFmtAll(t *testing.T) {
209209
}
210210

211211
testName := fi.Name()[:len(fi.Name())-10]
212-
inputPath := path.Join("../../testdata", fi.Name())
213-
goldenPath := path.Join("../../testdata", testName+".golden.sql")
212+
inputPath := filepath.Join("../../testdata", fi.Name())
213+
goldenPath := filepath.Join("../../testdata", testName+".golden.sql")
214214

215215
input, err := ioutil.ReadFile(inputPath)
216216
if err != nil {
@@ -231,7 +231,7 @@ func TestSqlFmtAll(t *testing.T) {
231231
}
232232

233233
if bytes.Compare(output, expected) != 0 {
234-
actualFileName := path.Join("tmp", fmt.Sprintf("%s.sql", testName))
234+
actualFileName := filepath.Join("tmp", fmt.Sprintf("%s.sql", testName))
235235
err = ioutil.WriteFile(actualFileName, output, os.ModePerm)
236236
if err != nil {
237237
t.Fatal(err)

integration_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8-
"path"
8+
"path/filepath"
99
"testing"
1010

1111
"github.com/jackc/sqlfmt"
@@ -27,8 +27,8 @@ func TestIntegration(t *testing.T) {
2727
}
2828

2929
testName := fi.Name()[:len(fi.Name())-10]
30-
inputPath := path.Join("testdata", fi.Name())
31-
goldenPath := path.Join("testdata", testName+".golden.sql")
30+
inputPath := filepath.Join("testdata", fi.Name())
31+
goldenPath := filepath.Join("testdata", testName+".golden.sql")
3232

3333
input, err := ioutil.ReadFile(inputPath)
3434
if err != nil {
@@ -54,7 +54,7 @@ func TestIntegration(t *testing.T) {
5454
stmt.RenderTo(r)
5555

5656
if outBuf.String() != string(expected) {
57-
actualFileName := path.Join("tmp", fmt.Sprintf("%s.sql", testName))
57+
actualFileName := filepath.Join("tmp", fmt.Sprintf("%s.sql", testName))
5858
err = ioutil.WriteFile(actualFileName, outBuf.Bytes(), os.ModePerm)
5959
if err != nil {
6060
t.Fatal(err)

0 commit comments

Comments
 (0)