| 1 | package testutilscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/internal/testutil`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.23.0 os/" |
| 6 | "path/filepathscip-go gomod github.com/golang/go/src go1.23.0 `path/filepath`/" |
| 7 | "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/" |
| 8 | |
| 9 | "github.com/dnaeon/go-vcr/recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/" |
| 10 | ) |
| 11 | |
| 12 | // NewVCRHTTPClient creates an *http.Client wired to a go-vcr recorder. |
| 13 | // Cassette files are stored under testdata/cassettes. |
| 14 | // If ANTHROPIC_LIVE=1, the recorder runs in recording mode; otherwise replay-only. |
| 15 | func NewVCRHTTPClientscip-go gomod github.com/anthropics/anthropic-sdk-go . `github.com/anthropics/anthropic-sdk-go/internal/testutil`/NewVCRHTTPClient().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#, cassetteName string) (*httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Client#, *recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/.Recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/Recorder#) { |
| 16 | t.Helperscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Helper().() |
| 17 | |
| 18 | mode := recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/.ModeReplayingscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/ModeReplaying. |
| 19 | if osscip-go gomod github.com/golang/go/src go1.23.0 os/.Getenvscip-go gomod github.com/golang/go/src go1.23.0 os/Getenv().("ANTHROPIC_LIVE") == "1" { |
| 20 | mode = recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/.ModeRecordingscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/ModeRecording. |
| 21 | } |
| 22 | |
| 23 | // Let go-vcr handle the .yaml extension to avoid accidental double suffixes |
| 24 | cassettePath := filepathscip-go gomod github.com/golang/go/src go1.23.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.23.0 `path/filepath`/Join().("testdata", "cassettes", cassetteName) |
| 25 | r, err := recorderscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/.NewAsModescip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/NewAsMode().(cassettePath, mode, nil) |
| 26 | if err != nil { |
| 27 | t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("failed to create recorder: %v", err) |
| 28 | } |
| 29 | |
| 30 | t.Cleanupscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Cleanup().(func() { |
| 31 | _ = r.Stopscip-go gomod github.com/dnaeon/go-vcr v1.2.0 `github.com/dnaeon/go-vcr/recorder`/Recorder#Stop().() |
| 32 | }) |
| 33 | |
| 34 | httpClient := &httpscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/.Clientscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Client#{Transportscip-go gomod github.com/golang/go/src go1.23.0 `net/http`/Client#Transport.: r} |
| 35 | return httpClient, r |
| 36 | } |