mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
Update flags to align with other var commands. (#14550)
This commit is contained in:
@@ -50,6 +50,24 @@ func TestVarListCommand_Offline(t *testing.T) {
|
||||
exitCode: 1,
|
||||
expectStdErrPrefix: "Error initializing client: invalid address",
|
||||
},
|
||||
{
|
||||
name: "missing template",
|
||||
args: []string{`-out=go-template`, "foo"},
|
||||
exitCode: 1,
|
||||
expectStdErrPrefix: errMissingTemplate,
|
||||
},
|
||||
{
|
||||
name: "unexpected_template",
|
||||
args: []string{`-out=json`, `-template="bad"`, "foo"},
|
||||
exitCode: 1,
|
||||
expectStdErrPrefix: errUnexpectedTemplate,
|
||||
},
|
||||
{
|
||||
name: "bad out",
|
||||
args: []string{`-out=bad`, "foo"},
|
||||
exitCode: 1,
|
||||
expectStdErrPrefix: errInvalidListOutFormat,
|
||||
},
|
||||
}
|
||||
for _, tC := range testCases {
|
||||
t.Run(tC.name, func(t *testing.T) {
|
||||
@@ -109,13 +127,6 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
|
||||
nsList := []string{api.DefaultNamespace, "ns1"}
|
||||
pathList := []string{"a/b/c", "a/b/c/d", "z/y", "z/y/x"}
|
||||
toJSON := func(in interface{}) string {
|
||||
b, err := json.MarshalIndent(in, "", " ")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(b))
|
||||
}
|
||||
variables := setupTestVariables(client, nsList, pathList)
|
||||
|
||||
testTmpl := `{{ range $i, $e := . }}{{if ne $i 0}}{{print "•"}}{{end}}{{printf "%v\t%v" .Namespace .Path}}{{end}}`
|
||||
@@ -150,12 +161,12 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
testCases := []testVarListTestCase{
|
||||
{
|
||||
name: "plaintext/not found",
|
||||
args: []string{"does/not/exist"},
|
||||
expectStdOut: msgVariableNotFound,
|
||||
args: []string{"-out=table", "does/not/exist"},
|
||||
expectStdOut: errNoMatchingVariables,
|
||||
},
|
||||
{
|
||||
name: "plaintext/single variable",
|
||||
args: []string{"a/b/c/d"},
|
||||
args: []string{"-out=table", "a/b/c/d"},
|
||||
expectStdOut: formatList([]string{
|
||||
"Namespace|Path|Last Updated",
|
||||
fmt.Sprintf(
|
||||
@@ -166,41 +177,41 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet",
|
||||
args: []string{"-q"},
|
||||
name: "plaintext/terse",
|
||||
args: []string{"-out=terse"},
|
||||
expectStdOut: strings.Join(variables.HavingNamespace(api.DefaultNamespace).Strings(), "\n"),
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet/prefix",
|
||||
args: []string{"-q", "a/b/c"},
|
||||
name: "plaintext/terse/prefix",
|
||||
args: []string{"-out=terse", "a/b/c"},
|
||||
expectStdOut: strings.Join(variables.HavingNSPrefix(api.DefaultNamespace, "a/b/c").Strings(), "\n"),
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet/filter",
|
||||
args: []string{"-q", "-filter", "VariableMetadata.Path == \"a/b/c\""},
|
||||
name: "plaintext/terse/filter",
|
||||
args: []string{"-out=terse", "-filter", "VariableMetadata.Path == \"a/b/c\""},
|
||||
expectStdOut: "a/b/c",
|
||||
expectStdErrPrefix: msgWarnFilterPerformance,
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet/paginated",
|
||||
args: []string{"-q", "-per-page=1"},
|
||||
name: "plaintext/terse/paginated",
|
||||
args: []string{"-out=terse", "-per-page=1"},
|
||||
expectStdOut: "a/b/c",
|
||||
expectStdErrPrefix: "Next page token",
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet/prefix/wildcard ns",
|
||||
args: []string{"-q", "-namespace", "*", "a/b/c/d"},
|
||||
name: "plaintext/terse/prefix/wildcard ns",
|
||||
args: []string{"-out=terse", "-namespace", "*", "a/b/c/d"},
|
||||
expectStdOut: strings.Join(variables.HavingPrefix("a/b/c/d").Strings(), "\n"),
|
||||
},
|
||||
{
|
||||
name: "plaintext/quiet/paginated/prefix/wildcard ns",
|
||||
args: []string{"-q", "-per-page=1", "-namespace", "*", "a/b/c/d"},
|
||||
name: "plaintext/terse/paginated/prefix/wildcard ns",
|
||||
args: []string{"-out=terse", "-per-page=1", "-namespace", "*", "a/b/c/d"},
|
||||
expectStdOut: variables.HavingPrefix("a/b/c/d").Strings()[0],
|
||||
expectStdErrPrefix: "Next page token",
|
||||
},
|
||||
{
|
||||
name: "json/not found",
|
||||
args: []string{"-json", "does/not/exist"},
|
||||
args: []string{"-out=json", "does/not/exist"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &SVMSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
@@ -210,7 +221,7 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "json/prefix",
|
||||
args: []string{"-json", "a"},
|
||||
args: []string{"-out=json", "a"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &SVMSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
@@ -220,7 +231,7 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "json/paginated",
|
||||
args: []string{"-json", "-per-page", "1"},
|
||||
args: []string{"-out=json", "-per-page", "1"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &PaginatedSVMSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
@@ -228,68 +239,32 @@ func TestVarListCommand_Online(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "json/quiet",
|
||||
args: []string{"-q", "-json"},
|
||||
expectStdOut: toJSON(variables.HavingNamespace(api.DefaultNamespace).Strings()),
|
||||
},
|
||||
{
|
||||
name: "json/quiet/paginated",
|
||||
args: []string{"-q", "-json", "-per-page", "1"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &PaginatedSVQuietSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
hasLength(t, 1),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "json/quiet/wildcard-ns",
|
||||
args: []string{"-q", "-json", "-namespace", "*"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &SVMSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
hasLength(t, variables.Len()),
|
||||
pathsEqual(t, variables),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "json/quiet/paginated/wildcard-ns",
|
||||
args: []string{"-q", "-json", "-per-page=1", "-namespace", "*"},
|
||||
jsonTest: &testVarListJSONTest{
|
||||
jsonDest: &PaginatedSVMSlice{},
|
||||
expectFns: []testVarListJSONTestExpectFn{
|
||||
hasLength(t, 1),
|
||||
pathsEqual(t, SVMSlice{variables[0]}),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
name: "template/not found",
|
||||
args: []string{"-t", testTmpl, "does/not/exist"},
|
||||
args: []string{"-out=go-template", "-template", testTmpl, "does/not/exist"},
|
||||
expectStdOut: "",
|
||||
},
|
||||
{
|
||||
name: "template/prefix",
|
||||
args: []string{"-t", testTmpl, "a/b/c/d"},
|
||||
args: []string{"-out=go-template", "-template", testTmpl, "a/b/c/d"},
|
||||
expectStdOut: "default\ta/b/c/d",
|
||||
},
|
||||
{
|
||||
name: "template/filter",
|
||||
args: []string{"-t", testTmpl, "-filter", "VariableMetadata.Path == \"a/b/c\""},
|
||||
args: []string{"-out=go-template", "-template", testTmpl, "-filter", "VariableMetadata.Path == \"a/b/c\""},
|
||||
expectStdOut: "default\ta/b/c",
|
||||
expectStdErrPrefix: msgWarnFilterPerformance,
|
||||
},
|
||||
{
|
||||
name: "template/paginated",
|
||||
args: []string{"-t", testTmpl, "-per-page=1"},
|
||||
args: []string{"-out=go-template", "-template", testTmpl, "-per-page=1"},
|
||||
expectStdOut: "default\ta/b/c",
|
||||
expectStdErrPrefix: "Next page token",
|
||||
},
|
||||
{
|
||||
name: "template/prefix/wildcard namespace",
|
||||
args: []string{"-namespace", "*", "-t", testTmpl, "a/b/c/d"},
|
||||
args: []string{"-namespace", "*", "-out=go-template", "-template", testTmpl, "a/b/c/d"},
|
||||
expectStdOut: "default\ta/b/c/d•ns1\ta/b/c/d",
|
||||
},
|
||||
}
|
||||
@@ -385,11 +360,14 @@ func setupTestVariables(c *api.Client, nsList, pathList []string) SVMSlice {
|
||||
return out
|
||||
}
|
||||
|
||||
func setupTestVariable(c *api.Client, ns, p string, out *SVMSlice) {
|
||||
testVar := &api.Variable{Items: map[string]string{"k": "v"}}
|
||||
c.Raw().Write("/v1/var/"+p, testVar, nil, &api.WriteOptions{Namespace: ns})
|
||||
v, _, _ := c.Variables().Read(p, &api.QueryOptions{Namespace: ns})
|
||||
func setupTestVariable(c *api.Client, ns, p string, out *SVMSlice) error {
|
||||
testVar := &api.Variable{
|
||||
Namespace: ns,
|
||||
Path: p,
|
||||
Items: map[string]string{"k": "v"}}
|
||||
v, _, err := c.Variables().Create(testVar, &api.WriteOptions{Namespace: ns})
|
||||
*out = append(*out, *v.Metadata())
|
||||
return err
|
||||
}
|
||||
|
||||
type NSPather interface {
|
||||
|
||||
Reference in New Issue
Block a user