Skip to content

Commit

Permalink
chore: Satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kuck committed Nov 29, 2023
1 parent 7823a01 commit 8a6ff0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions database/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const reservedChars = "!#$%&'()*+,/:;=?@[]"

const baseUsername = "username"

const dbPrefix = "database://"

// TestUserUnencodedReservedURLChars documents the behavior of using unencoded reserved characters in usernames with
// net/url Parse()
func TestUserUnencodedReservedURLChars(t *testing.T) {
scheme := "database://"
scheme := dbPrefix
urlSuffix := "password@localhost:12345/myDB?someParam=true"
urlSuffixAndSep := ":" + urlSuffix

Expand Down Expand Up @@ -64,7 +66,7 @@ func TestUserUnencodedReservedURLChars(t *testing.T) {
testedChars := make([]string, 0, len(reservedChars))
for _, tc := range testcases {
testedChars = append(testedChars, tc.char)
t.Run("reserved char "+tc.char, func(t *testing.T) {
t.Run("reserved char="+tc.char, func(t *testing.T) {
s := scheme + baseUsername + tc.char + urlSuffixAndSep
u, err := url.Parse(s)
if err == nil {
Expand Down Expand Up @@ -98,13 +100,13 @@ func TestUserUnencodedReservedURLChars(t *testing.T) {
}

func TestUserEncodedReservedURLChars(t *testing.T) {
scheme := "database://"
scheme := dbPrefix
urlSuffix := "password@localhost:12345/myDB?someParam=true"
urlSuffixAndSep := ":" + urlSuffix

for _, c := range reservedChars {
c := string(c)
t.Run("reserved char "+c, func(t *testing.T) {
t.Run("reserved char="+c, func(t *testing.T) {
encodedChar := "%" + hex.EncodeToString([]byte(c))
s := scheme + baseUsername + encodedChar + urlSuffixAndSep
expectedUsername := baseUsername + c
Expand Down
14 changes: 8 additions & 6 deletions source/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
st "github.com/golang-migrate/migrate/v4/source/testing"
)

const filePrefix = "file://"

func Test(t *testing.T) {
tmpDir := t.TempDir()

Expand All @@ -29,7 +31,7 @@ func Test(t *testing.T) {
mustWriteFile(t, tmpDir, "7_foobar.down.sql", "7 down")

f := &File{}
d, err := f.Open("file://" + tmpDir)
d, err := f.Open(filePrefix + tmpDir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -48,7 +50,7 @@ func TestOpen(t *testing.T) {
}

f := &File{}
_, err := f.Open("file://" + tmpDir) // absolute path
_, err := f.Open(filePrefix + tmpDir) // absolute path
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -125,7 +127,7 @@ func TestOpenWithDuplicateVersion(t *testing.T) {
mustWriteFile(t, tmpDir, "1_bar.up.sql", "") // 1 up

f := &File{}
_, err := f.Open("file://" + tmpDir)
_, err := f.Open(filePrefix + tmpDir)
if err == nil {
t.Fatal("expected err")
}
Expand All @@ -135,7 +137,7 @@ func TestClose(t *testing.T) {
tmpDir := t.TempDir()

f := &File{}
d, err := f.Open("file://" + tmpDir)
d, err := f.Open(filePrefix + tmpDir)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -172,7 +174,7 @@ func BenchmarkOpen(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
f := &File{}
_, err := f.Open("file://" + dir)
_, err := f.Open(filePrefix + dir)
if err != nil {
b.Error(err)
}
Expand All @@ -188,7 +190,7 @@ func BenchmarkNext(b *testing.B) {
}
}()
f := &File{}
d, _ := f.Open("file://" + dir)
d, _ := f.Open(filePrefix + dir)
b.ResetTimer()
v, err := d.First()
for n := 0; n < b.N; n++ {
Expand Down

0 comments on commit 8a6ff0c

Please sign in to comment.