package ollama import ( "net/http" "testing" "time" ) func TestNew_DefaultTimeout(t *testing.T) { p := New(Config{}) got := responseHeaderTimeout(t, p) if got != defaultTimeout { t.Errorf("ResponseHeaderTimeout = %v, want %v (defaultTimeout = 300s for local)", got, defaultTimeout) } // Sanity: ollama default must be longer than cloud (60s). if defaultTimeout < 200*time.Second { t.Errorf("ollama defaultTimeout = %v, expected >= 200s for local cold start", defaultTimeout) } } func TestNew_ConfigTimeout(t *testing.T) { want := 42 * time.Second p := New(Config{Timeout: want}) got := responseHeaderTimeout(t, p) if got != want { t.Errorf("ResponseHeaderTimeout = %v, want %v", got, want) } } func TestNew_HTTPClientOverridesTimeout(t *testing.T) { consumerTimeout := 7 * time.Second consumerClient := &http.Client{ Transport: &http.Transport{ResponseHeaderTimeout: consumerTimeout}, } p := New(Config{ HTTPClient: consumerClient, Timeout: 999 * time.Second, }) got := responseHeaderTimeout(t, p) if got != consumerTimeout { t.Errorf("ResponseHeaderTimeout = %v, want %v (consumer's value)", got, consumerTimeout) } if p.client.HTTPClient() != consumerClient { t.Errorf("Provider is not using the consumer's HTTPClient") } } func responseHeaderTimeout(t *testing.T, p *Provider) time.Duration { t.Helper() hc := p.client.HTTPClient() if hc == nil { t.Fatal("Provider has nil http.Client") } transport, ok := hc.Transport.(*http.Transport) if !ok { t.Fatalf("Provider http.Client.Transport is %T, want *http.Transport", hc.Transport) } return transport.ResponseHeaderTimeout }