mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* notes Signed-off-by: Joe Elliott <[email protected]> * bench Signed-off-by: Joe Elliott <[email protected]> * reduce cost of setting requestURI Signed-off-by: Joe Elliott <[email protected]> * Swap to interface Signed-off-by: Joe Elliott <[email protected]> * wip: cache failing Signed-off-by: Joe Elliott <[email protected]> * Response interface in the async pipeline Signed-off-by: Joe Elliott <[email protected]> * changelog Signed-off-by: Joe Elliott <[email protected]> * remove all hidden context propagation Signed-off-by: Joe Elliott <[email protected]> * lint and remove notes Signed-off-by: Joe Elliott <[email protected]> * its gonna be one of those linty kind of days Signed-off-by: Joe Elliott <[email protected]> * more lint Signed-off-by: Joe Elliott <[email protected]> --------- Signed-off-by: Joe Elliott <[email protected]>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAdjustsResponseCode(t *testing.T) {
|
|
nextFn := func(status int) RoundTripper {
|
|
return RoundTripperFunc(func(_ Request) (*http.Response, error) {
|
|
return &http.Response{StatusCode: status}, nil
|
|
})
|
|
}
|
|
|
|
tcs := []struct {
|
|
actualCode int
|
|
expectedCode int
|
|
}{
|
|
{actualCode: 400, expectedCode: 500},
|
|
{actualCode: 429, expectedCode: 429},
|
|
{actualCode: 500, expectedCode: 500},
|
|
{actualCode: 200, expectedCode: 200},
|
|
{actualCode: 418, expectedCode: 500},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
retryWare := NewStatusCodeAdjustWare()
|
|
handler := retryWare.Wrap(nextFn(tc.actualCode))
|
|
req := httptest.NewRequest("GET", "http://example.com", nil)
|
|
res, err := handler.RoundTrip(NewHTTPRequest(req))
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, res.StatusCode, tc.expectedCode)
|
|
}
|
|
}
|
|
|
|
func TestAdjustsResponseCodeTeapotAllowed(t *testing.T) {
|
|
nextFn := func(status int) RoundTripper {
|
|
return RoundTripperFunc(func(_ Request) (*http.Response, error) {
|
|
return &http.Response{StatusCode: status}, nil
|
|
})
|
|
}
|
|
|
|
tcs := []struct {
|
|
actualCode int
|
|
expectedCode int
|
|
}{
|
|
{actualCode: 400, expectedCode: 500},
|
|
{actualCode: 429, expectedCode: 429},
|
|
{actualCode: 500, expectedCode: 500},
|
|
{actualCode: 200, expectedCode: 200},
|
|
{actualCode: 418, expectedCode: 418},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
retryWare := NewStatusCodeAdjustWareWithAllowedCode(418)
|
|
handler := retryWare.Wrap(nextFn(tc.actualCode))
|
|
req := httptest.NewRequest("GET", "http://example.com", nil)
|
|
res, err := handler.RoundTrip(NewHTTPRequest(req))
|
|
|
|
require.NoError(t, err)
|
|
require.Equal(t, res.StatusCode, tc.expectedCode)
|
|
}
|
|
}
|