Establish connections using bookmark ID only (#619)

* Establish connections using bookmark ID only
* Refactor specs
* Extra tests
* Fix homedir assertion for bookmarks path
* Fix newline in the warning message
* Check for bookmark file existence before reading
* Connect code restructure
This commit is contained in:
Dan Sosedoff
2022-12-19 12:33:13 -06:00
committed by GitHub
parent 0b9e7cdb4e
commit 69233cd769
11 changed files with 411 additions and 325 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/jackc/pgpassfile"
"github.com/jessevdk/go-flags"
"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
)
@@ -154,6 +155,13 @@ func ParseOptions(args []string) (Options, error) {
}
}
if opts.BookmarksDir == "" {
path, err := homedir.Dir()
if err == nil {
opts.BookmarksDir = filepath.Join(path, ".pgweb/bookmarks")
}
}
return opts, nil
}

View File

@@ -2,12 +2,19 @@ package command
import (
"os"
"path/filepath"
"testing"
"github.com/mitchellh/go-homedir"
"github.com/stretchr/testify/assert"
)
func TestParseOptions(t *testing.T) {
var hdir string
if d, err := homedir.Dir(); err == nil {
hdir = d
}
t.Run("defaults", func(t *testing.T) {
opts, err := ParseOptions([]string{})
assert.NoError(t, err)
@@ -22,6 +29,7 @@ func TestParseOptions(t *testing.T) {
assert.Equal(t, false, opts.Cors)
assert.Equal(t, "*", opts.CorsOrigin)
assert.Equal(t, "", opts.Passfile)
assert.Equal(t, filepath.Join(hdir, ".pgweb/bookmarks"), opts.BookmarksDir)
})
t.Run("sessions", func(t *testing.T) {