mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-25 01:04:55 +03:00
db55986980
- Support for ingest cache, download cache, and progress bars.
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package yamlstore
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/cli/flag"
|
|
"github.com/neilotoole/sq/testh/tu"
|
|
)
|
|
|
|
func Test_getConfigDirFromFlag(t *testing.T) {
|
|
testCases := []struct {
|
|
in []string
|
|
want string
|
|
wantOK bool
|
|
wantErr bool
|
|
}{
|
|
{in: nil, wantOK: false},
|
|
{in: []string{}, wantOK: false},
|
|
{in: []string{"sq", "--" + flag.Config + "=/home"}, wantOK: true, want: "/home"},
|
|
{in: []string{"sq", "--" + flag.Config, "/home"}, wantOK: true, want: "/home"},
|
|
{in: []string{"sq", "some", "args"}, wantOK: false, want: ""},
|
|
{in: []string{"sq", "--some=value", "args"}, wantOK: false, want: ""},
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tu.Name(i, strings.Join(tc.in, " ")), func(t *testing.T) {
|
|
got, gotOK, gotErr := getConfigDirFromFlag(tc.in)
|
|
if tc.wantErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, gotErr)
|
|
if !tc.wantOK {
|
|
require.False(t, gotOK)
|
|
require.Empty(t, got)
|
|
return
|
|
}
|
|
|
|
require.True(t, tc.wantOK)
|
|
require.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
}
|