github.com/cli/cli@v1.14.1-0.20210902173923-1af6a669e342/pkg/cmdutil/args_test.go (about)

     1  package cmdutil
     2  
     3  import "testing"
     4  
     5  func TestMinimumArgs(t *testing.T) {
     6  	tests := []struct {
     7  		N    int
     8  		Args []string
     9  	}{
    10  		{
    11  			N:    1,
    12  			Args: []string{"v1.2.3"},
    13  		},
    14  		{
    15  			N:    2,
    16  			Args: []string{"v1.2.3", "cli/cli"},
    17  		},
    18  	}
    19  
    20  	for _, test := range tests {
    21  		if got := MinimumArgs(test.N, "")(nil, test.Args); got != nil {
    22  			t.Errorf("Got: %v, Want: (nil)", got)
    23  		}
    24  	}
    25  }
    26  
    27  func TestMinimumNs_with_error(t *testing.T) {
    28  	tests := []struct {
    29  		N             int
    30  		CustomMessage string
    31  		WantMessage   string
    32  	}{
    33  		{
    34  			N:             1,
    35  			CustomMessage: "A custom msg",
    36  			WantMessage:   "A custom msg",
    37  		},
    38  		{
    39  			N:             1,
    40  			CustomMessage: "",
    41  			WantMessage:   "requires at least 1 arg(s), only received 0",
    42  		},
    43  	}
    44  
    45  	for _, test := range tests {
    46  		if got := MinimumArgs(test.N, test.CustomMessage)(nil, nil); got.Error() != test.WantMessage {
    47  			t.Errorf("Got: %v, Want: %v", got, test.WantMessage)
    48  		}
    49  	}
    50  }