Validation is cheap so do it more
This commit is contained in:
@@ -95,38 +95,38 @@ func TestContentCompletionNoteValidation(t *testing.T) {
|
||||
|
||||
func TestTitleLengthNoteValidation(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
title string
|
||||
expectedError bool
|
||||
name string
|
||||
title string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
name: "Max valid title",
|
||||
title: strings.Repeat("0", models.NoteTitleMaxLength),
|
||||
name: "Max valid title",
|
||||
title: strings.Repeat("0", models.NoteTitleMaxLength),
|
||||
expectedError: false,
|
||||
},
|
||||
{
|
||||
name: "Just over max valid title",
|
||||
title: strings.Repeat("1", models.NoteTitleMaxLength + 1),
|
||||
name: "Just over max valid title",
|
||||
title: strings.Repeat("1", models.NoteTitleMaxLength+1),
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "Double max valid title",
|
||||
title: strings.Repeat("Bd", models.NoteTitleMaxLength),
|
||||
name: "Double max valid title",
|
||||
title: strings.Repeat("Bd", models.NoteTitleMaxLength),
|
||||
expectedError: true,
|
||||
},
|
||||
{
|
||||
name: "Random overmax valid title length",
|
||||
title: strings.Repeat("1", models.NoteTitleMaxLength + rand.IntN(150)),
|
||||
name: "Random overmax valid title length",
|
||||
title: strings.Repeat("1", models.NoteTitleMaxLength+rand.IntN(150)),
|
||||
expectedError: true,
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
note := models.Note{
|
||||
Title: tc.title,
|
||||
Content: "Perfectly valid content " + tc.title,
|
||||
Title: tc.title,
|
||||
Content: "Perfectly valid content " + tc.title,
|
||||
LastUpdate: time.Now(),
|
||||
ID: 1,
|
||||
ID: 1,
|
||||
}
|
||||
err := note.Validate()
|
||||
|
||||
@@ -143,4 +143,4 @@ func TestTitleLengthNoteValidation(t *testing.T) {
|
||||
fmt.Printf("Test case '%s' passed.\n", tc.name)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user