Files
threshold/internal/cmd/main_test.go
T
b6df5693b5 Add generic read/update/delete commands (#3992)
* Add generic read/update/delete commands

This adds three generic commands that use the resource prefix to
determine the subcommand to run and pass through args over to that
subcommand. Since this occurs very early on and to avoid loading
essentially every internal resource package, I moved subtype definitions
to globals.

This replaces #3967

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* De-duplicate Subtype code (#4031)

Co-authored-by: Timothy Messier <tim.messier@gmail.com>

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Co-authored-by: Timothy Messier <tim.messier@gmail.com>
2023-11-15 19:55:46 -05:00

74 lines
1.6 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestHandleHighLevelShortcuts(t *testing.T) {
t.Parallel()
tests := []struct {
name string
in []string
out []string
expRunOpts bool
}{
{
name: "zero length",
},
{
name: "one length",
in: []string{"foo"},
out: []string{"foo"},
},
{
name: "not a match",
in: []string{"foo", "bar"},
out: []string{"foo", "bar"},
},
{
name: "unhandled prefix",
in: []string{"read", "bar"},
out: []string{"read", "bar"},
},
{
name: "handled read",
in: []string{"read", "hst_1234567890"},
out: []string{"hosts", "read"},
expRunOpts: true,
},
{
name: "handled delete",
in: []string{"delete", "clvlt_1234567890"},
out: []string{"credential-libraries", "delete"},
expRunOpts: true,
},
{
name: "handled update",
in: []string{"update", "g_1234567890"},
out: []string{"groups", "update"},
expRunOpts: true,
},
{
name: "handled subtype update",
in: []string{"update", "credspk_1234567890"},
out: []string{"credentials", "update", "ssh-private-key"},
expRunOpts: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var runOpts RunOptions
out := handleHighLevelShortcuts(tc.in, &runOpts)
assert.EqualValues(t, tc.out, out)
if tc.expRunOpts {
assert.Equal(t, tc.in[1], runOpts.ImplicitId)
}
})
}
}