(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func (s) TestStringWithAllowedValues(t *testing.T) { |
| 39 | const defaultVal = "default" |
| 40 | tests := []struct { |
| 41 | args string |
| 42 | allowed []string |
| 43 | wantVal string |
| 44 | wantErr bool |
| 45 | }{ |
| 46 | {"-workloads=all", []string{"unary", "streaming", "all"}, "all", false}, |
| 47 | {"-workloads=disallowed", []string{"unary", "streaming", "all"}, defaultVal, true}, |
| 48 | } |
| 49 | |
| 50 | for _, test := range tests { |
| 51 | flag.CommandLine = flag.NewFlagSet("test", flag.ContinueOnError) |
| 52 | var w = StringWithAllowedValues("workloads", defaultVal, "usage", test.allowed) |
| 53 | err := flag.CommandLine.Parse([]string{test.args}) |
| 54 | switch { |
| 55 | case !test.wantErr && err != nil: |
| 56 | t.Errorf("failed to parse command line args {%v}: %v", test.args, err) |
| 57 | case test.wantErr && err == nil: |
| 58 | t.Errorf("flag.Parse(%v) = nil, want non-nil error", test.args) |
| 59 | default: |
| 60 | if *w != test.wantVal { |
| 61 | t.Errorf("flag value is %v, want %v", *w, test.wantVal) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func (s) TestDurationSlice(t *testing.T) { |
| 68 | defaultVal := []time.Duration{time.Second, time.Nanosecond} |
nothing calls this directly
no test coverage detected