fix(pricing): fallback to direct fetch after proxy transport errors
This commit is contained in:
@@ -5,6 +5,7 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -44,6 +45,47 @@ func TestIsRetriablePricingFetchErrorRecognizesEOF(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchRawPricingPageFallsBackWithoutProxyOnRetriableProxyFailure(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
oldHTTPProxy, hadHTTPProxy := os.LookupEnv("HTTP_PROXY")
|
||||
oldHTTPSProxy, hadHTTPSProxy := os.LookupEnv("HTTPS_PROXY")
|
||||
oldNoProxy, hadNoProxy := os.LookupEnv("NO_PROXY")
|
||||
defer func() {
|
||||
if hadHTTPProxy {
|
||||
_ = os.Setenv("HTTP_PROXY", oldHTTPProxy)
|
||||
} else {
|
||||
_ = os.Unsetenv("HTTP_PROXY")
|
||||
}
|
||||
if hadHTTPSProxy {
|
||||
_ = os.Setenv("HTTPS_PROXY", oldHTTPSProxy)
|
||||
} else {
|
||||
_ = os.Unsetenv("HTTPS_PROXY")
|
||||
}
|
||||
if hadNoProxy {
|
||||
_ = os.Setenv("NO_PROXY", oldNoProxy)
|
||||
} else {
|
||||
_ = os.Unsetenv("NO_PROXY")
|
||||
}
|
||||
}()
|
||||
|
||||
_ = os.Setenv("HTTP_PROXY", "http://127.0.0.1:1")
|
||||
_ = os.Unsetenv("HTTPS_PROXY")
|
||||
_ = os.Unsetenv("NO_PROXY")
|
||||
|
||||
client := &http.Client{Timeout: 2 * time.Second}
|
||||
body, err := fetchRawPricingPage(server.URL, "", client)
|
||||
if err != nil {
|
||||
t.Fatalf("fetchRawPricingPage returned error with proxy fallback enabled: %v", err)
|
||||
}
|
||||
if body != "ok" {
|
||||
t.Fatalf("body = %q, want ok", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFallbackModalityCanonicalizesAliases(t *testing.T) {
|
||||
if got := fallbackModality("image"); got != "vision" {
|
||||
t.Fatalf("fallbackModality(image) = %q, want vision", got)
|
||||
|
||||
Reference in New Issue
Block a user