openai_previous_response_id_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package service
  2. import "testing"
  3. func TestClassifyOpenAIPreviousResponseIDKind(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. id string
  7. want string
  8. }{
  9. {name: "empty", id: " ", want: OpenAIPreviousResponseIDKindEmpty},
  10. {name: "response_id", id: "resp_0906a621bc423a8d0169a108637ef88197b74b0e2f37ba358f", want: OpenAIPreviousResponseIDKindResponseID},
  11. {name: "message_id", id: "msg_123456", want: OpenAIPreviousResponseIDKindMessageID},
  12. {name: "item_id", id: "item_abcdef", want: OpenAIPreviousResponseIDKindMessageID},
  13. {name: "unknown", id: "foo_123456", want: OpenAIPreviousResponseIDKindUnknown},
  14. }
  15. for _, tc := range tests {
  16. t.Run(tc.name, func(t *testing.T) {
  17. if got := ClassifyOpenAIPreviousResponseIDKind(tc.id); got != tc.want {
  18. t.Fatalf("ClassifyOpenAIPreviousResponseIDKind(%q)=%q want=%q", tc.id, got, tc.want)
  19. }
  20. })
  21. }
  22. }
  23. func TestIsOpenAIPreviousResponseIDLikelyMessageID(t *testing.T) {
  24. if !IsOpenAIPreviousResponseIDLikelyMessageID("msg_123") {
  25. t.Fatal("expected msg_123 to be identified as message id")
  26. }
  27. if IsOpenAIPreviousResponseIDLikelyMessageID("resp_123") {
  28. t.Fatal("expected resp_123 not to be identified as message id")
  29. }
  30. }