(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestRequiredFields(t *testing.T) { |
| 15 | type ( |
| 16 | test1 struct { |
| 17 | Name string |
| 18 | Value string `help:"field value" required:"false"` |
| 19 | } |
| 20 | |
| 21 | test2 struct { |
| 22 | Name string |
| 23 | Value string `help:"field value" required:"true"` |
| 24 | } |
| 25 | |
| 26 | test3 struct { |
| 27 | Name string `required:"true"` |
| 28 | Value string `help:"field value" required:"true"` |
| 29 | } |
| 30 | ) |
| 31 | |
| 32 | tests := []struct { |
| 33 | name string |
| 34 | cfg interface{} |
| 35 | want []string |
| 36 | }{ |
| 37 | { |
| 38 | name: "no required fields", |
| 39 | cfg: &test1{}, |
| 40 | want: nil, |
| 41 | }, |
| 42 | { |
| 43 | name: "one required field", |
| 44 | cfg: &test2{}, |
| 45 | want: []string{"Value"}, |
| 46 | }, |
| 47 | { |
| 48 | name: "all required fields", |
| 49 | cfg: &test3{}, |
| 50 | want: []string{"Name", "Value"}, |
| 51 | }, |
| 52 | } |
| 53 | for _, tt := range tests { |
| 54 | t.Run(tt.name, func(t *testing.T) { |
| 55 | if got := baker.RequiredFields(tt.cfg); !reflect.DeepEqual(got, tt.want) { |
| 56 | t.Errorf("RequiredFields() = %v, want %v", got, tt.want) |
| 57 | } |
| 58 | }) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestCheckRequiredFields(t *testing.T) { |
| 63 | type ( |
nothing calls this directly
no test coverage detected