MCPcopy Create free account
hub / github.com/google/go-cloud / NewGCPClient

Function NewGCPClient

internal/testing/setup/setup.go:151–174  ·  view source on GitHub ↗

NewGCPClient creates a new HTTPClient for testing against GCP. If the test is in --record mode, the client will call out to GCP, and the results are recorded in a replay file. Otherwise, the session reads a replay file and runs the test as a replay, which never makes an outgoing HTTP call and uses

(ctx context.Context, t *testing.T)

Source from the content-addressed store, hash-verified

149// Otherwise, the session reads a replay file and runs the test as a replay,
150// which never makes an outgoing HTTP call and uses fake credentials.
151func NewGCPClient(ctx context.Context, t *testing.T) (client *gcp.HTTPClient, rt http.RoundTripper, done func()) {
152 t.Helper()
153
154 c, cleanup, _ := NewRecordReplayClient(ctx, t, func(r *httpreplay.Recorder) {
155 r.ClearQueryParams("Expires")
156 r.ClearQueryParams("Signature")
157 r.ClearHeaders("Expires")
158 r.ClearHeaders("Signature")
159 r.ClearHeaders("X-Goog-Gcs-Idempotency-Token")
160 r.ClearHeaders("User-Agent")
161 })
162 transport := c.Transport
163 if *Record {
164 creds, err := gcp.DefaultCredentials(ctx)
165 if err != nil {
166 t.Fatalf("failed to get default credentials: %v", err)
167 }
168 c, err = hrgoog.RecordClient(ctx, c, option.WithTokenSource(gcp.CredentialsTokenSource(creds)))
169 if err != nil {
170 t.Fatal(err)
171 }
172 }
173 return &gcp.HTTPClient{Client: *c}, transport, cleanup
174}
175
176// NewGCPgRPCConn creates a new connection for testing against GCP via gRPC.
177//

Callers 2

newHarnessFunction · 0.92
TestOpenBucketFunction · 0.92

Calls 3

DefaultCredentialsFunction · 0.92
CredentialsTokenSourceFunction · 0.92
NewRecordReplayClientFunction · 0.85

Tested by 2

newHarnessFunction · 0.74
TestOpenBucketFunction · 0.74