Refactor building connection string from options
This commit is contained in:
@@ -19,7 +19,7 @@ func Test_Invalid_Url(t *testing.T) {
|
||||
|
||||
for _, val := range examples {
|
||||
opts.Url = val
|
||||
str, err := BuildString(opts)
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
|
||||
assert.Equal(t, "", str)
|
||||
assert.Error(t, err)
|
||||
@@ -29,14 +29,14 @@ func Test_Invalid_Url(t *testing.T) {
|
||||
|
||||
func Test_Valid_Url(t *testing.T) {
|
||||
url := "postgres://myhost/database"
|
||||
str, err := BuildString(command.Options{Url: url})
|
||||
str, err := BuildStringFromOptions(command.Options{Url: url})
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, url, str)
|
||||
}
|
||||
|
||||
func Test_Url_And_Ssl_Flag(t *testing.T) {
|
||||
str, err := BuildString(command.Options{
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://myhost/database",
|
||||
Ssl: "disable",
|
||||
})
|
||||
@@ -46,13 +46,13 @@ func Test_Url_And_Ssl_Flag(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Localhost_Url_And_No_Ssl_Flag(t *testing.T) {
|
||||
str, err := BuildString(command.Options{
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://localhost/database",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://localhost/database?sslmode=disable", str)
|
||||
|
||||
str, err = BuildString(command.Options{
|
||||
str, err = BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://127.0.0.1/database",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
@@ -60,14 +60,14 @@ func Test_Localhost_Url_And_No_Ssl_Flag(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Localhost_Url_And_Ssl_Flag(t *testing.T) {
|
||||
str, err := BuildString(command.Options{
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://localhost/database",
|
||||
Ssl: "require",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://localhost/database?sslmode=require", str)
|
||||
|
||||
str, err = BuildString(command.Options{
|
||||
str, err = BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://127.0.0.1/database",
|
||||
Ssl: "require",
|
||||
})
|
||||
@@ -76,13 +76,13 @@ func Test_Localhost_Url_And_Ssl_Flag(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Localhost_Url_And_Ssl_Arg(t *testing.T) {
|
||||
str, err := BuildString(command.Options{
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://localhost/database?sslmode=require",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://localhost/database?sslmode=require", str)
|
||||
|
||||
str, err = BuildString(command.Options{
|
||||
str, err = BuildStringFromOptions(command.Options{
|
||||
Url: "postgres://127.0.0.1/database?sslmode=require",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
@@ -90,7 +90,7 @@ func Test_Localhost_Url_And_Ssl_Arg(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Flag_Args(t *testing.T) {
|
||||
str, err := BuildString(command.Options{
|
||||
str, err := BuildStringFromOptions(command.Options{
|
||||
Host: "host",
|
||||
Port: 5432,
|
||||
User: "user",
|
||||
@@ -111,12 +111,12 @@ func Test_Localhost(t *testing.T) {
|
||||
DbName: "db",
|
||||
}
|
||||
|
||||
str, err := BuildString(opts)
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://user:password@localhost:5432/db?sslmode=disable", str)
|
||||
|
||||
opts.Host = "127.0.0.1"
|
||||
str, err = BuildString(opts)
|
||||
str, err = BuildStringFromOptions(opts)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://user:password@127.0.0.1:5432/db?sslmode=disable", str)
|
||||
}
|
||||
@@ -131,7 +131,7 @@ func Test_Localhost_And_Ssl(t *testing.T) {
|
||||
Ssl: "require",
|
||||
}
|
||||
|
||||
str, err := BuildString(opts)
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://user:password@localhost:5432/db?sslmode=require", str)
|
||||
}
|
||||
@@ -139,18 +139,18 @@ func Test_Localhost_And_Ssl(t *testing.T) {
|
||||
func Test_No_User(t *testing.T) {
|
||||
opts := command.Options{Host: "host", Port: 5432, DbName: "db"}
|
||||
u, _ := user.Current()
|
||||
str, err := BuildString(opts)
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, fmt.Sprintf("postgres://%s@host:5432/db", u.Username), str)
|
||||
assert.Equal(t, fmt.Sprintf("postgres://%s:@host:5432/db", u.Username), str)
|
||||
}
|
||||
|
||||
func Test_Port(t *testing.T) {
|
||||
opts := command.Options{Host: "host", User: "user", Port: 5000, DbName: "db"}
|
||||
str, err := BuildString(opts)
|
||||
str, err := BuildStringFromOptions(opts)
|
||||
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "postgres://user@host:5000/db", str)
|
||||
assert.Equal(t, "postgres://user:@host:5000/db", str)
|
||||
}
|
||||
|
||||
func Test_Blank(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user