2023-04-26 18:16:42 +03:00
|
|
|
package yamlstore
|
2023-04-19 08:28:09 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-04-19 08:28:09 +03:00
|
|
|
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/cli/flag"
|
2024-01-15 04:45:34 +03:00
|
|
|
"github.com/neilotoole/sq/testh/tu"
|
2023-04-19 08:28:09 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2024-01-15 04:45:34 +03:00
|
|
|
t.Run(tu.Name(i, strings.Join(tc.in, " ")), func(t *testing.T) {
|
2023-04-19 08:28:09 +03:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|