Files
threshold/internal/cmd/main_test.go
T
Jeff MitchellandJohan Brandhorst-Satzkorn 0bf60996c5 Add generic read/update/delete commands (#3967)
* 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.

* Update main.go

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

* Update changelog and remove another deprecated command

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2023-11-01 16:24:16 -04: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)
}
})
}
}