(t *testing.T)
| 60 | } |
| 61 | |
| 62 | func TestCheckRequiredFields(t *testing.T) { |
| 63 | type ( |
| 64 | test1 struct { |
| 65 | Name string |
| 66 | Value string `help:"field value" required:"false"` |
| 67 | } |
| 68 | |
| 69 | test2 struct { |
| 70 | Name string |
| 71 | Value string `help:"field value" required:"true"` |
| 72 | } |
| 73 | |
| 74 | test3 struct { |
| 75 | Name string `required:"true"` |
| 76 | Value string `help:"field value" required:"true"` |
| 77 | } |
| 78 | ) |
| 79 | |
| 80 | tests := []struct { |
| 81 | name string |
| 82 | val interface{} |
| 83 | want string |
| 84 | }{ |
| 85 | { |
| 86 | name: "no required fields", |
| 87 | val: &test1{}, |
| 88 | want: "", |
| 89 | }, |
| 90 | { |
| 91 | name: "one missing required field ", |
| 92 | val: &test2{Name: "name", Value: ""}, |
| 93 | want: "Value", |
| 94 | }, |
| 95 | { |
| 96 | name: "one present required field ", |
| 97 | val: &test2{Name: "name", Value: "value"}, |
| 98 | want: "", |
| 99 | }, |
| 100 | { |
| 101 | name: "all required fields and all are missing", |
| 102 | val: &test3{}, |
| 103 | want: "Name", |
| 104 | }, |
| 105 | { |
| 106 | name: "all required fields but the first missing", |
| 107 | val: &test3{Value: "value"}, |
| 108 | want: "Name", |
| 109 | }, |
| 110 | { |
| 111 | name: "all required fields and all are present", |
| 112 | val: &test3{Name: "name", Value: "value"}, |
| 113 | want: "", |
| 114 | }, |
| 115 | } |
| 116 | for _, tt := range tests { |
| 117 | t.Run(tt.name, func(t *testing.T) { |
| 118 | if got := baker.CheckRequiredFields(tt.val); got != tt.want { |
| 119 | t.Errorf("CheckRequiredFields() = %v, want %v", got, tt.want) |
nothing calls this directly
no test coverage detected