(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestExtractStatusCode(t *testing.T) { |
| 13 | t.Parallel() |
| 14 | |
| 15 | tests := []struct { |
| 16 | name string |
| 17 | input string |
| 18 | want int |
| 19 | }{ |
| 20 | {name: "Status", input: "received status 429 from upstream", want: 429}, |
| 21 | {name: "StatusCode", input: "status code: 503", want: 503}, |
| 22 | {name: "HTTP", input: "http 502 bad gateway", want: 502}, |
| 23 | {name: "Standalone", input: "got 504 from upstream", want: 504}, |
| 24 | {name: "MultipleStandaloneCodesReturnFirstMatch", input: "retrying 503 after 429", want: 503}, |
| 25 | {name: "MixedCaseViaCallerLowering", input: "HTTP 503 bad gateway", want: 503}, |
| 26 | {name: "PortNumberIPIsNotStatus", input: "dial tcp 10.0.0.1:503: connection refused", want: 0}, |
| 27 | {name: "PortNumberHostIsNotStatus", input: "proxy.internal:502 unreachable", want: 0}, |
| 28 | {name: "PortNumberDialIsNotStatus", input: "dial tcp 172.16.0.5:429: refused", want: 0}, |
| 29 | {name: "PortThenRealStatusReturnsRealStatus", input: "proxy at 10.0.0.1:500 returned 503", want: 503}, |
| 30 | {name: "HTTP2StreamIDIsNotStatus", input: "stream error: stream ID 401; INTERNAL_ERROR; received from peer", want: 0}, |
| 31 | {name: "HTTP2StreamIDWithPunctuationIsNotStatus", input: "stream error: stream ID: 503; PROTOCOL_ERROR; received from peer", want: 0}, |
| 32 | {name: "HTTP2StreamIDThenExplicitStatusReturnsStatus", input: "stream error: stream ID 455; status 503 from upstream", want: 503}, |
| 33 | {name: "NoFabricatedOverloadStatus", input: "anthropic overloaded_error", want: 0}, |
| 34 | {name: "NoFabricatedRateLimitStatus", input: "too many requests", want: 0}, |
| 35 | {name: "NoFabricatedBadGatewayStatus", input: "bad gateway", want: 0}, |
| 36 | {name: "NoFabricatedServiceUnavailableStatus", input: "service unavailable", want: 0}, |
| 37 | {name: "NoStatus", input: "boom", want: 0}, |
| 38 | } |
| 39 | |
| 40 | for _, tt := range tests { |
| 41 | t.Run(tt.name, func(t *testing.T) { |
| 42 | t.Parallel() |
| 43 | require.Equal(t, tt.want, chaterror.ExtractStatusCodeForTest(strings.ToLower(tt.input))) |
| 44 | }) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func TestDetectProvider(t *testing.T) { |
| 49 | t.Parallel() |
nothing calls this directly
no test coverage detected