Test blank connection options
This commit is contained in:
parent
09ad707d94
commit
58ee238db4
@ -35,6 +35,10 @@ func formatConnectionUrl(opts Options) (string, error) {
|
|||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func connectionSettingsBlank(opts Options) bool {
|
||||||
|
return opts.Host == "" && opts.User == "" && opts.DbName == "" && opts.Url == ""
|
||||||
|
}
|
||||||
|
|
||||||
func buildConnectionString(opts Options) (string, error) {
|
func buildConnectionString(opts Options) (string, error) {
|
||||||
if opts.Url != "" {
|
if opts.Url != "" {
|
||||||
return formatConnectionUrl(opts)
|
return formatConnectionUrl(opts)
|
||||||
|
@ -156,3 +156,10 @@ func Test_Port(t *testing.T) {
|
|||||||
assert.Equal(t, nil, err)
|
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) {
|
||||||
|
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"}))
|
||||||
|
}
|
||||||
|
9
main.go
9
main.go
@ -91,15 +91,8 @@ func getConnectionString() string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func connectionSettingsBlank() bool {
|
|
||||||
return options.Host == "" &&
|
|
||||||
options.User == "" &&
|
|
||||||
options.DbName == "" &&
|
|
||||||
options.Url == ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func initClient() {
|
func initClient() {
|
||||||
if connectionSettingsBlank() {
|
if connectionSettingsBlank(options) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user