terraform/internal/command/arguments/workspace_show_test.go
Sarah French e24abdf6ff
refactor: Update workspace select and delete subcommands to use the arguments package for parsing arguments and flags (#38429)
* feat: Add `workspace show`-related code to arguments package

* refactor: Update `workspace show` to use the arguments package when parsing arguments

* refactor: Split code for workspace subcommands into separate files in arguments package

* refactor: Move code common to all workspace commands into separate file in arguments package

* feat: Add `workspace delete`-related code to arguments package

* refactor: Update `workspace delete` to use the arguments package when parsing arguments
2026-04-29 08:05:49 -04:00

80 lines
1.6 KiB
Go

// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: BUSL-1.1
package arguments
import (
"testing"
"github.com/hashicorp/terraform/internal/tfdiags"
)
func TestParseWorkspaceShow_valid(t *testing.T) {
testCases := map[string]struct {
args []string
want *WorkspaceShow
}{
"defaults": {
nil,
&WorkspaceShow{
Workspace: Workspace{
ViewType: ViewHuman,
},
},
},
"currently there is no validation about too many arguments": {
[]string{"bar"},
&WorkspaceShow{
Workspace: Workspace{
ViewType: ViewHuman,
},
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
got, diags := ParseWorkspaceShow(tc.args)
if len(diags) > 0 {
t.Fatalf("unexpected diags: %v", diags)
}
if *got != *tc.want {
t.Fatalf("unexpected result\n got: %#v\nwant: %#v", got, tc.want)
}
})
}
}
func TestParseWorkspaceShow_invalid(t *testing.T) {
testCases := map[string]struct {
args []string
want *WorkspaceShow
wantDiags tfdiags.Diagnostics
}{
"unknown flag": {
[]string{"-boop"},
&WorkspaceShow{
Workspace: Workspace{
ViewType: ViewHuman,
},
},
tfdiags.Diagnostics{
tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
"flag provided but not defined: -boop",
),
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
got, gotDiags := ParseWorkspaceShow(tc.args)
if *got != *tc.want {
t.Fatalf("unexpected result\n got: %#v\nwant: %#v", got, tc.want)
}
tfdiags.AssertDiagnosticsMatch(t, gotDiags, tc.wantDiags)
})
}
}