MCPcopy Create free account
hub / github.com/driangle/taskmd / TestValidate_RequiredFields

Function TestValidate_RequiredFields

sdk/go/validator/validator_test.go:9–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func 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
64func TestValidate_InvalidFieldValues(t *testing.T) {
65 tests := []struct {

Callers

nothing calls this directly

Calls 2

ValidateMethod · 0.95
NewValidatorFunction · 0.85

Tested by

no test coverage detected