From 58ee238db450b459537f59cf90fbed243485d399 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Wed, 17 Dec 2014 21:56:15 -0600 Subject: [PATCH] Test blank connection options --- connection_string.go | 4 ++++ connection_string_test.go | 7 +++++++ main.go | 9 +-------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/connection_string.go b/connection_string.go index 59e524c..20cfbae 100644 --- a/connection_string.go +++ b/connection_string.go @@ -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) diff --git a/connection_string_test.go b/connection_string_test.go index cdd3d2b..c4fcfae 100644 --- a/connection_string_test.go +++ b/connection_string_test.go @@ -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"})) +} diff --git a/main.go b/main.go index 175a9cf..6e5f595 100644 --- a/main.go +++ b/main.go @@ -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 }