mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-18 21:52:28 +03:00
ed9aa38a67
* Expose source.Set.Data() method * jsonw.writeJSON cleaned up * sq add now respects --json * Location strings are subject to more scrutiny * Ignore .db files in project dir * sq add is more restrictive about location string * source.RedactedLocation now uses 'xxxxx' per stdlib url.URL.Redacted() * Update changelog for v0.23.0 * typos
97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
package source_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/stringz"
|
|
"github.com/neilotoole/sq/testh/tutil"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/libsq/source"
|
|
)
|
|
|
|
func TestWubble(t *testing.T) {
|
|
t.Log(strings.ToUpper(stringz.Uniq32()))
|
|
}
|
|
|
|
func TestRedactedLocation(t *testing.T) {
|
|
testCases := []struct {
|
|
loc string
|
|
want string
|
|
}{
|
|
{
|
|
loc: "/path/to/sqlite.db",
|
|
want: "/path/to/sqlite.db",
|
|
},
|
|
{
|
|
loc: "/path/to/data.xlsx",
|
|
want: "/path/to/data.xlsx",
|
|
},
|
|
{
|
|
loc: "https://path/to/data.xlsx",
|
|
want: "https://path/to/data.xlsx",
|
|
},
|
|
{
|
|
loc: "http://path/to/data.xlsx",
|
|
want: "http://path/to/data.xlsx",
|
|
},
|
|
{
|
|
loc: "sqlserver://sq:p_ssW0rd@localhost?database=sqtest",
|
|
want: "sqlserver://sq:xxxxx@localhost?database=sqtest",
|
|
},
|
|
{
|
|
loc: "postgres://sq:p_ssW0rd@localhost/sqtest?sslmode=disable",
|
|
want: "postgres://sq:xxxxx@localhost/sqtest?sslmode=disable",
|
|
},
|
|
{
|
|
loc: "mysql://sq:p_ssW0rd@localhost:3306/sqtest",
|
|
want: "mysql://sq:xxxxx@localhost:3306/sqtest",
|
|
},
|
|
{
|
|
loc: "sqlite3:///path/to/sqlite.db",
|
|
want: "sqlite3:///path/to/sqlite.db",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tutil.Name(tc.loc), func(t *testing.T) {
|
|
src := &source.Source{Location: tc.loc}
|
|
got := src.RedactedLocation()
|
|
t.Logf("%s --> %s", src.Location, got)
|
|
require.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestShortLocation(t *testing.T) {
|
|
testCases := []struct {
|
|
tname string
|
|
loc string
|
|
want string
|
|
}{
|
|
{tname: "sqlite3_scheme", loc: "sqlite3:///path/to/sqlite.db", want: "sqlite.db"},
|
|
{tname: "sqlite3", loc: "/path/to/sqlite.db", want: "sqlite.db"},
|
|
{tname: "xlsx", loc: "/path/to/data.xlsx", want: "data.xlsx"},
|
|
{tname: "https", loc: "https://path/to/data.xlsx", want: "data.xlsx"},
|
|
{tname: "http", loc: "http://path/to/data.xlsx", want: "data.xlsx"},
|
|
{tname: "sqlserver", loc: "sqlserver://sq:p_ssw0rd@localhost?database=sqtest", want: "sq@localhost/sqtest"},
|
|
{
|
|
tname: "postgres", loc: "postgres://sq:p_ssW0rd@localhost/sqtest?sslmode=disable",
|
|
want: "sq@localhost/sqtest",
|
|
},
|
|
{tname: "mysql", loc: "mysql://sq:p_ssW0rd@localhost:3306/sqtest", want: "sq@localhost:3306/sqtest"},
|
|
{tname: "mysql", loc: "mysql://sq:p_ssW0rd@localhost/sqtest", want: "sq@localhost/sqtest"},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tc.tname, func(t *testing.T) {
|
|
got := source.ShortLocation(tc.loc)
|
|
t.Logf("%s --> %s", tc.loc, got)
|
|
require.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
}
|