github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/arguments/view_test.go (about)

     1  package arguments
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/google/go-cmp/cmp"
     7  )
     8  
     9  func TestParseView(t *testing.T) {
    10  	testCases := map[string]struct {
    11  		args     []string
    12  		want     *View
    13  		wantArgs []string
    14  	}{
    15  		"nil": {
    16  			nil,
    17  			&View{NoColor: false, CompactWarnings: false},
    18  			nil,
    19  		},
    20  		"empty": {
    21  			[]string{},
    22  			&View{NoColor: false, CompactWarnings: false},
    23  			[]string{},
    24  		},
    25  		"none matching": {
    26  			[]string{"-foo", "bar", "-baz"},
    27  			&View{NoColor: false, CompactWarnings: false},
    28  			[]string{"-foo", "bar", "-baz"},
    29  		},
    30  		"no-color": {
    31  			[]string{"-foo", "-no-color", "-baz"},
    32  			&View{NoColor: true, CompactWarnings: false},
    33  			[]string{"-foo", "-baz"},
    34  		},
    35  		"compact-warnings": {
    36  			[]string{"-foo", "-compact-warnings", "-baz"},
    37  			&View{NoColor: false, CompactWarnings: true},
    38  			[]string{"-foo", "-baz"},
    39  		},
    40  		"both": {
    41  			[]string{"-foo", "-no-color", "-compact-warnings", "-baz"},
    42  			&View{NoColor: true, CompactWarnings: true},
    43  			[]string{"-foo", "-baz"},
    44  		},
    45  		"both, resulting in empty args": {
    46  			[]string{"-no-color", "-compact-warnings"},
    47  			&View{NoColor: true, CompactWarnings: true},
    48  			[]string{},
    49  		},
    50  	}
    51  	for name, tc := range testCases {
    52  		t.Run(name, func(t *testing.T) {
    53  			got, gotArgs := ParseView(tc.args)
    54  			if *got != *tc.want {
    55  				t.Errorf("unexpected result\n got: %#v\nwant: %#v", got, tc.want)
    56  			}
    57  			if !cmp.Equal(gotArgs, tc.wantArgs) {
    58  				t.Errorf("unexpected args\n got: %#v\nwant: %#v", gotArgs, tc.wantArgs)
    59  			}
    60  		})
    61  	}
    62  }