(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestValidate_RequiredFields(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | name string |
| 12 | tasks []*model.Task |
| 13 | wantErrs int |
| 14 | }{ |
| 15 | { |
| 16 | name: "valid task with all required fields", |
| 17 | tasks: []*model.Task{ |
| 18 | { |
| 19 | ID: "001", |
| 20 | Title: "Test Task", |
| 21 | }, |
| 22 | }, |
| 23 | wantErrs: 0, |
| 24 | }, |
| 25 | { |
| 26 | name: "missing ID", |
| 27 | tasks: []*model.Task{ |
| 28 | { |
| 29 | Title: "Test Task", |
| 30 | }, |
| 31 | }, |
| 32 | wantErrs: 1, |
| 33 | }, |
| 34 | { |
| 35 | name: "missing title", |
| 36 | tasks: []*model.Task{ |
| 37 | { |
| 38 | ID: "001", |
| 39 | }, |
| 40 | }, |
| 41 | wantErrs: 1, |
| 42 | }, |
| 43 | { |
| 44 | name: "missing both ID and title", |
| 45 | tasks: []*model.Task{ |
| 46 | {}, |
| 47 | }, |
| 48 | wantErrs: 2, |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | for _, tt := range tests { |
| 53 | t.Run(tt.name, func(t *testing.T) { |
| 54 | v := NewValidator(false) |
| 55 | result := v.Validate(tt.tasks) |
| 56 | |
| 57 | if result.Errors != tt.wantErrs { |
| 58 | t.Errorf("Validate() errors = %d, want %d", result.Errors, tt.wantErrs) |
| 59 | } |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestValidate_InvalidFieldValues(t *testing.T) { |
| 65 | tests := []struct { |
nothing calls this directly
no test coverage detected