Files
llm-intelligence/scripts/official_pricing_import_common_test.go
phamnazage-jpg 958245537a feat(imports): add real pricing and subscription collectors
Add plan catalog and subscription schema support, seed baselines, and real importers for core domestic subscriptions plus stable official pricing sources.

This commit also hardens the shared fetch layers so the importers can support live collection and database writes instead of relying on manual placeholders alone.
2026-05-15 22:32:57 +08:00

50 lines
1.2 KiB
Go

//go:build llm_script
package main
import (
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"
"time"
)
func TestFetchRawPricingPageRetriesTransientStatus(t *testing.T) {
var attempts int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
current := atomic.AddInt32(&attempts, 1)
if current == 1 {
http.Error(w, "temporary", http.StatusServiceUnavailable)
return
}
_, _ = w.Write([]byte("ok"))
}))
defer server.Close()
client := &http.Client{Timeout: 2 * time.Second}
body, err := fetchRawPricingPage(server.URL, "", client)
if err != nil {
t.Fatalf("fetchRawPricingPage returned error: %v", err)
}
if body != "ok" {
t.Fatalf("body = %q, want ok", body)
}
if got := atomic.LoadInt32(&attempts); got != 2 {
t.Fatalf("attempts = %d, want 2", got)
}
}
func TestIsRetriablePricingFetchErrorRecognizesEOF(t *testing.T) {
if !isRetriablePricingFetchError(errString("unexpected EOF")) {
t.Fatalf("expected EOF to be retriable")
}
if isRetriablePricingFetchError(errString("bad request")) {
t.Fatalf("expected bad request to be non-retriable")
}
}
type errString string
func (e errString) Error() string { return string(e) }