29 lines
915 B
Go
29 lines
915 B
Go
package handler
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidatePhotoMetadata(t *testing.T) {
|
|
for _, tt := range []struct {
|
|
name, date, location, activity string
|
|
valid bool
|
|
}{
|
|
{"clear fields", "", "", "", true},
|
|
{"leap day", "2024-02-29", "北京颐和园", "第一次一起看日落", true},
|
|
{"invalid day", "2026-02-29", "", "", false},
|
|
{"date format", "2026-2-1", "", "", false},
|
|
{"time not accepted", "2026-10-07 09:54", "", "", false},
|
|
{"unicode at limit", "", strings.Repeat("景", 200), strings.Repeat("爱", 200), true},
|
|
{"location too long", "", strings.Repeat("景", 201), "", false},
|
|
{"story too long", "", "", strings.Repeat("爱", 201), false},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := validatePhotoMetadata(tt.date, tt.location, tt.activity); (got == nil) != tt.valid {
|
|
t.Fatalf("valid=%v, error=%v", tt.valid, got)
|
|
}
|
|
})
|
|
}
|
|
}
|