Move bookmark default port parsing to readServerConfig func

This commit is contained in:
Dan Sosedoff 2016-11-15 22:01:42 -06:00
parent 59018287de
commit 0510634db7
2 changed files with 6 additions and 5 deletions

View File

@ -49,6 +49,11 @@ func readServerConfig(path string) (Bookmark, error) {
}
_, err = toml.Decode(string(buff), &bookmark)
if bookmark.Port == 0 {
bookmark.Port = 5432
}
return bookmark, err
}
@ -101,9 +106,5 @@ func GetBookmark(bookmarkPath string, bookmarkName string) (Bookmark, error) {
return Bookmark{}, fmt.Errorf("couldn't find a bookmark with name %s", bookmarkName)
}
if bookmark.Port == 0 {
bookmark.Port = 5432
}
return bookmark, nil
}

View File

@ -36,7 +36,7 @@ func Test_Bookmark_URL(t *testing.T) {
assert.Equal(t, nil, err)
assert.Equal(t, "postgres://username:password@host:port/database?sslmode=disable", bookmark.Url)
assert.Equal(t, "", bookmark.Host)
assert.Equal(t, 0, bookmark.Port)
assert.Equal(t, 5432, bookmark.Port)
assert.Equal(t, "", bookmark.User)
assert.Equal(t, "", bookmark.Database)
assert.Equal(t, "", bookmark.Ssl)