Add method that returns if bookmark's ssh is empty

We will use this method in upcoming commit to create
client from stored bookmark.
This commit is contained in:
akarki15
2016-11-10 01:21:49 -05:00
parent 474c439076
commit f4fb5744ef
2 changed files with 23 additions and 0 deletions

View File

@@ -23,6 +23,9 @@ type Bookmark struct {
Ssh shared.SSHInfo `json:"ssh"` // SSH tunnel config
}
func (b Bookmark) SSHInfoIsEmpty() bool {
return b.Ssh.User == "" && b.Ssh.Host == "" && b.Ssh.Port == ""
}
func readServerConfig(path string) (Bookmark, error) {
bookmark := Bookmark{}

View File

@@ -3,6 +3,7 @@ package bookmarks
import (
"testing"
"github.com/sosedoff/pgweb/pkg/shared"
"github.com/stretchr/testify/assert"
)
@@ -69,3 +70,22 @@ func Test_ReadBookmarks(t *testing.T) {
assert.Equal(t, nil, err)
assert.Equal(t, 2, len(bookmarks))
}
func Test_Bookmark_SSHInfoIsEmpty(t *testing.T) {
emptySSH := shared.SSHInfo{
Host: "",
Port: "",
User: "",
}
populatedSSH := shared.SSHInfo{
Host: "localhost",
Port: "8080",
User: "postgres",
}
b := Bookmark{Ssh: emptySSH}
assert.True(t, b.SSHInfoIsEmpty())
b.Ssh = populatedSSH
assert.False(t, b.SSHInfoIsEmpty())
}