mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package arguments
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestParseView(t *testing.T) {
|
|
testCases := map[string]struct {
|
|
args []string
|
|
want *View
|
|
wantArgs []string
|
|
}{
|
|
"nil": {
|
|
nil,
|
|
&View{NoColor: false, CompactWarnings: false},
|
|
nil,
|
|
},
|
|
"empty": {
|
|
[]string{},
|
|
&View{NoColor: false, CompactWarnings: false},
|
|
[]string{},
|
|
},
|
|
"none matching": {
|
|
[]string{"-foo", "bar", "-baz"},
|
|
&View{NoColor: false, CompactWarnings: false},
|
|
[]string{"-foo", "bar", "-baz"},
|
|
},
|
|
"no-color": {
|
|
[]string{"-foo", "-no-color", "-baz"},
|
|
&View{NoColor: true, CompactWarnings: false},
|
|
[]string{"-foo", "-baz"},
|
|
},
|
|
"compact-warnings": {
|
|
[]string{"-foo", "-compact-warnings", "-baz"},
|
|
&View{NoColor: false, CompactWarnings: true},
|
|
[]string{"-foo", "-baz"},
|
|
},
|
|
"both": {
|
|
[]string{"-foo", "-no-color", "-compact-warnings", "-baz"},
|
|
&View{NoColor: true, CompactWarnings: true},
|
|
[]string{"-foo", "-baz"},
|
|
},
|
|
"both, resulting in empty args": {
|
|
[]string{"-no-color", "-compact-warnings"},
|
|
&View{NoColor: true, CompactWarnings: true},
|
|
[]string{},
|
|
},
|
|
}
|
|
for name, tc := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
got, gotArgs := ParseView(tc.args)
|
|
if *got != *tc.want {
|
|
t.Errorf("unexpected result\n got: %#v\nwant: %#v", got, tc.want)
|
|
}
|
|
if !cmp.Equal(gotArgs, tc.wantArgs) {
|
|
t.Errorf("unexpected args\n got: %#v\nwant: %#v", gotArgs, tc.wantArgs)
|
|
}
|
|
})
|
|
}
|
|
}
|