Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

37 строки
1.1KB

  1. package mapping
  2. import (
  3. "errors"
  4. "strings"
  5. "testing"
  6. )
  7. func TestShortErr_DefaultLimit(t *testing.T) {
  8. t.Parallel()
  9. msg := "x" + strings.Repeat("a", 260)
  10. got := shortErr(errors.New(msg))
  11. if len(got) != 183 {
  12. t.Fatalf("expected default truncated len 183, got %d", len(got))
  13. }
  14. if !strings.HasSuffix(got, "...") {
  15. t.Fatalf("expected ellipsis suffix, got %q", got)
  16. }
  17. }
  18. func TestShortErr_OpenAICompatibleEmptyContentUsesLongerLimit(t *testing.T) {
  19. t.Parallel()
  20. prefix := "empty openai-compatible response content (choices_len=1; choices0={index:number,finish_reason:string,message:object}; message={content:array,role:string}; message_content_type=array; message_content_len=0; top={choices:array,id:string}) "
  21. got := shortErr(errors.New(prefix + strings.Repeat("x", 260)))
  22. if len(got) != 423 {
  23. t.Fatalf("expected openai-compatible truncated len 423, got %d", len(got))
  24. }
  25. if !strings.HasPrefix(got, "empty openai-compatible response content (") {
  26. t.Fatalf("expected openai-compatible prefix, got %q", got)
  27. }
  28. if !strings.HasSuffix(got, "...") {
  29. t.Fatalf("expected ellipsis suffix, got %q", got)
  30. }
  31. }