...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/utilities/string_array_flag_test.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/utilities

     1  package utilities_test
     2  
     3  import (
     4  	"flag"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
     9  )
    10  
    11  func TestStringArrayFlag(t *testing.T) {
    12  	tests := []struct {
    13  		name  string
    14  		flags []string
    15  		want  string
    16  	}{
    17  		{
    18  			name:  "No Value",
    19  			flags: []string{},
    20  			want:  "",
    21  		},
    22  		{
    23  			name:  "Single Value",
    24  			flags: []string{"--my_flag=1"},
    25  			want:  "1",
    26  		},
    27  		{
    28  			name:  "Repeated Value",
    29  			flags: []string{"--my_flag=1", "--my_flag=2"},
    30  			want:  "1,2",
    31  		},
    32  		{
    33  			name:  "Repeated Same Value",
    34  			flags: []string{"--my_flag=1", "--my_flag=1"},
    35  			want:  "1,1",
    36  		},
    37  	}
    38  	for _, tt := range tests {
    39  		t.Run(tt.name, func(t *testing.T) {
    40  			flagSet := flag.NewFlagSet("test", flag.PanicOnError)
    41  			result := utilities.StringArrayFlag(flagSet, "my_flag", "repeated flag")
    42  			if err := flagSet.Parse(tt.flags); err != nil {
    43  				t.Errorf("flagSet.Parse() failed with %v", err)
    44  			}
    45  			if !reflect.DeepEqual(result.String(), tt.want) {
    46  				t.Errorf("StringArrayFlag() = %v, want %v", result.String(), tt.want)
    47  			}
    48  		})
    49  	}
    50  }
    51  

View as plain text