openai_gateway_grok_405_test.go 894 B

1234567891011121314151617181920212223242526272829
  1. package service
  2. import (
  3. "net/http"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestShouldFailoverUpstreamError_405IsFailoverEligible(t *testing.T) {
  8. svc := &OpenAIGatewayService{}
  9. assert.True(t, svc.shouldFailoverUpstreamError(http.StatusMethodNotAllowed),
  10. "405 should trigger failover so sticky sessions can escape to healthy accounts")
  11. }
  12. func TestShouldFailoverUpstreamError_ExistingCodesStillWork(t *testing.T) {
  13. svc := &OpenAIGatewayService{}
  14. failoverCodes := []int{401, 402, 403, 405, 429, 529, 500, 502, 503, 504}
  15. for _, code := range failoverCodes {
  16. assert.True(t, svc.shouldFailoverUpstreamError(code), "status %d should trigger failover", code)
  17. }
  18. nonFailoverCodes := []int{200, 201, 400, 404, 408, 422}
  19. for _, code := range nonFailoverCodes {
  20. assert.False(t, svc.shouldFailoverUpstreamError(code), "status %d should NOT trigger failover", code)
  21. }
  22. }