| 119 | } |
| 120 | |
| 121 | func TestOptions_AddFlags_ChecksToRun(t *testing.T) { |
| 122 | t.Parallel() |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | opts *Options |
| 126 | expected []string |
| 127 | }{ |
| 128 | { |
| 129 | name: "custom options", |
| 130 | opts: &Options{ |
| 131 | ChecksToRun: []string{"check1", "check2"}, |
| 132 | }, |
| 133 | expected: []string{"check1", "check2"}, |
| 134 | }, |
| 135 | } |
| 136 | |
| 137 | for _, tt := range tests { |
| 138 | t.Run(tt.name, func(t *testing.T) { |
| 139 | t.Parallel() |
| 140 | e := []string{} |
| 141 | cmd := &cobra.Command{} |
| 142 | tt.opts.AddFlags(cmd) |
| 143 | for _, f := range strings.Split(cmd.Flag(FlagChecks).Value.String(), ",") { |
| 144 | f = strings.TrimPrefix(f, "[") |
| 145 | f = strings.TrimSuffix(f, "]") |
| 146 | e = append(e, f) |
| 147 | } |
| 148 | if !cmp.Equal(e, tt.expected) { |
| 149 | t.Errorf("expected FlagChecks to be %q, but got %q", tt.expected, e) |
| 150 | } |
| 151 | }) |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func TestOptions_AddFlags_Format(t *testing.T) { |
| 156 | t.Parallel() |