34 рядки
836 B
Go
34 рядки
836 B
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateListTitle(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{name: "trims", input: " Groceries ", want: "Groceries"},
|
|
{name: "empty", input: "", wantErr: true},
|
|
{name: "spaces only", input: " ", wantErr: true},
|
|
{name: "max length", input: strings.Repeat("a", 120), want: strings.Repeat("a", 120)},
|
|
{name: "too long", input: strings.Repeat("a", 121), wantErr: true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := validateListTitle(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("validateListTitle() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
if got != tt.want {
|
|
t.Fatalf("validateListTitle() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|