Test blank connection options

This commit is contained in:
Dan Sosedoff 2014-12-17 21:56:15 -06:00
parent 09ad707d94
commit 58ee238db4
3 changed files with 12 additions and 8 deletions

View File

@ -35,6 +35,10 @@ func formatConnectionUrl(opts Options) (string, error) {
return url, nil
}
func connectionSettingsBlank(opts Options) bool {
return opts.Host == "" && opts.User == "" && opts.DbName == "" && opts.Url == ""
}
func buildConnectionString(opts Options) (string, error) {
if opts.Url != "" {
return formatConnectionUrl(opts)

View File

@ -156,3 +156,10 @@ func Test_Port(t *testing.T) {
assert.Equal(t, nil, err)
assert.Equal(t, "postgres://user@host:5000/db", str)
}
func Test_Blank(t *testing.T) {
assert.Equal(t, true, connectionSettingsBlank(Options{}))
assert.Equal(t, false, connectionSettingsBlank(Options{Host: "host", User: "user"}))
assert.Equal(t, false, connectionSettingsBlank(Options{Host: "host", User: "user", DbName: "db"}))
assert.Equal(t, false, connectionSettingsBlank(Options{Url: "url"}))
}

View File

@ -91,15 +91,8 @@ func getConnectionString() string {
return str
}
func connectionSettingsBlank() bool {
return options.Host == "" &&
options.User == "" &&
options.DbName == "" &&
options.Url == ""
}
func initClient() {
if connectionSettingsBlank() {
if connectionSettingsBlank(options) {
return
}