Set the type of Bookmark.Port to int
We know that a port is a number. Lets enforce that rule at type level by setting it so. This commit also adjusts test funcs and helper data to fit Port's new int type.
This commit is contained in:
parent
0e88e3e1f4
commit
038cb620c6
@ -1,5 +1,5 @@
|
|||||||
host = "localhost"
|
host = "localhost"
|
||||||
port = "5432"
|
port = 5432
|
||||||
user = "postgres"
|
user = "postgres"
|
||||||
database = "mydatabase"
|
database = "mydatabase"
|
||||||
ssl = "disable"
|
ssl = "disable"
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
host = "localhost"
|
|
||||||
port = 5432
|
|
||||||
user = "postgres"
|
|
||||||
database = "mydatabase"
|
|
||||||
ssl = "disable"
|
|
@ -15,7 +15,7 @@ import (
|
|||||||
type Bookmark struct {
|
type Bookmark struct {
|
||||||
Url string `json:"url"` // Postgres connection URL
|
Url string `json:"url"` // Postgres connection URL
|
||||||
Host string `json:"host"` // Server hostname
|
Host string `json:"host"` // Server hostname
|
||||||
Port string `json:"port"` // Server port
|
Port int `json:"port"` // Server port
|
||||||
User string `json:"user"` // Database user
|
User string `json:"user"` // Database user
|
||||||
Password string `json:"password"` // User password
|
Password string `json:"password"` // User password
|
||||||
Database string `json:"database"` // Database name
|
Database string `json:"database"` // Database name
|
||||||
|
@ -14,10 +14,6 @@ func Test_Invalid_Bookmark_Files(t *testing.T) {
|
|||||||
_, err = readServerConfig("../../data/invalid.toml")
|
_, err = readServerConfig("../../data/invalid.toml")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "Near line 1, key 'invalid encoding': Near line 2: Expected key separator '=', but got '\\n' instead.", err.Error())
|
assert.Equal(t, "Near line 1, key 'invalid encoding': Near line 2: Expected key separator '=', but got '\\n' instead.", err.Error())
|
||||||
|
|
||||||
_, err = readServerConfig("../../data/invalid_port.toml")
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Equal(t, "Type mismatch for 'bookmarks.Bookmark.Port': Expected string but found 'int64'.", err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Bookmark(t *testing.T) {
|
func Test_Bookmark(t *testing.T) {
|
||||||
@ -25,7 +21,7 @@ func Test_Bookmark(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, "localhost", bookmark.Host)
|
assert.Equal(t, "localhost", bookmark.Host)
|
||||||
assert.Equal(t, "5432", bookmark.Port)
|
assert.Equal(t, 5432, bookmark.Port)
|
||||||
assert.Equal(t, "postgres", bookmark.User)
|
assert.Equal(t, "postgres", bookmark.User)
|
||||||
assert.Equal(t, "mydatabase", bookmark.Database)
|
assert.Equal(t, "mydatabase", bookmark.Database)
|
||||||
assert.Equal(t, "disable", bookmark.Ssl)
|
assert.Equal(t, "disable", bookmark.Ssl)
|
||||||
@ -39,7 +35,7 @@ func Test_Bookmark_URL(t *testing.T) {
|
|||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, "postgres://username:password@host:port/database?sslmode=disable", bookmark.Url)
|
assert.Equal(t, "postgres://username:password@host:port/database?sslmode=disable", bookmark.Url)
|
||||||
assert.Equal(t, "", bookmark.Host)
|
assert.Equal(t, "", bookmark.Host)
|
||||||
assert.Equal(t, "", bookmark.Port)
|
assert.Equal(t, 0, bookmark.Port)
|
||||||
assert.Equal(t, "", bookmark.User)
|
assert.Equal(t, "", bookmark.User)
|
||||||
assert.Equal(t, "", bookmark.Database)
|
assert.Equal(t, "", bookmark.Database)
|
||||||
assert.Equal(t, "", bookmark.Ssl)
|
assert.Equal(t, "", bookmark.Ssl)
|
||||||
@ -75,7 +71,7 @@ func Test_GetBookmark(t *testing.T) {
|
|||||||
expBookmark := Bookmark{
|
expBookmark := Bookmark{
|
||||||
|
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: "5432",
|
Port: 5432,
|
||||||
User: "postgres",
|
User: "postgres",
|
||||||
Password: "",
|
Password: "",
|
||||||
Database: "mydatabase",
|
Database: "mydatabase",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user