-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from fraenky8/ISSUE-34
ISSUE-34: Support unix socket connections
- Loading branch information
Showing
18 changed files
with
274 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package database | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/fraenky8/tables-to-go/pkg/settings" | ||
) | ||
|
||
func TestMySQL_DSN(t *testing.T) { | ||
tests := []struct { | ||
desc string | ||
settings func() *settings.Settings | ||
expected func(*settings.Settings) string | ||
}{ | ||
{ | ||
desc: "no username given, defaults to `root` with tcp", | ||
settings: func() *settings.Settings { | ||
s := settings.New() | ||
s.DbType = settings.DBTypeMySQL | ||
s.Pswd = "mysecretpassword" | ||
s.DbName = "my-cool-db" | ||
s.Port = "3306" | ||
return s | ||
}, | ||
expected: func(s *settings.Settings) string { | ||
return "root:mysecretpassword@tcp(127.0.0.1:3306)/my-cool-db" | ||
}, | ||
}, | ||
{ | ||
desc: "username given, with socket", | ||
settings: func() *settings.Settings { | ||
s := settings.New() | ||
s.DbType = settings.DBTypeMySQL | ||
s.User = "admin" | ||
s.Pswd = "mysecretpassword" | ||
s.DbName = "my-cool-db" | ||
s.Socket = "/tmp/mysql.sock" | ||
return s | ||
}, | ||
expected: func(s *settings.Settings) string { | ||
return "admin:mysecretpassword@unix(/tmp/mysql.sock)/my-cool-db" | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.desc, func(t *testing.T) { | ||
db := NewMySQL(test.settings()) | ||
actual := db.DSN() | ||
assert.Equal(t, test.expected(db.Settings), actual) | ||
}) | ||
} | ||
} |
Oops, something went wrong.