fix
This commit is contained in:
@@ -109,11 +109,23 @@ func TestCompleteJSON_returnsRetryError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProductEnhanceUser_truncates(t *testing.T) {
|
||||
long := strings.Repeat("x", 2000)
|
||||
long := strings.Repeat("x", MaxProductDescRunes+500)
|
||||
u := ProductEnhanceUser("Cat", "Name", long, map[string]any{"brand": "B"})
|
||||
if len([]rune(u)) > 900 {
|
||||
// Category/Name/Attrs overhead + MaxProductDescRunes of description.
|
||||
if len([]rune(u)) > MaxProductDescRunes+200 {
|
||||
t.Fatalf("user too long: %d", len([]rune(u)))
|
||||
}
|
||||
descIdx := strings.Index(u, "Description: ")
|
||||
if descIdx < 0 {
|
||||
t.Fatalf("missing Description: in %q", u)
|
||||
}
|
||||
descPart := u[descIdx+len("Description: "):]
|
||||
if i := strings.Index(descPart, "\n"); i >= 0 {
|
||||
descPart = descPart[:i]
|
||||
}
|
||||
if len([]rune(descPart)) > MaxProductDescRunes {
|
||||
t.Fatalf("description runes=%d want <= %d", len([]rune(descPart)), MaxProductDescRunes)
|
||||
}
|
||||
if !strings.Contains(u, "brand") {
|
||||
t.Fatalf("%s", u)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user