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

Function FakeGCPDefaultCredentials

internal/testing/setup/setup.go:244–262  ·  view source on GitHub ↗

FakeGCPDefaultCredentials sets up the environment with fake GCP credentials. It returns a cleanup function.

(t *testing.T)

Source from the content-addressed store, hash-verified

242// FakeGCPDefaultCredentials sets up the environment with fake GCP credentials.
243// It returns a cleanup function.
244func FakeGCPDefaultCredentials(t *testing.T) func() {
245 t.Helper()
246
247 const envVar = "GOOGLE_APPLICATION_CREDENTIALS"
248 jsonCred := []byte(`{"client_id": "foo.apps.googleusercontent.com", "client_secret": "bar", "refresh_token": "baz", "type": "authorized_user"}`)
249
250 f, err := os.CreateTemp(t.TempDir(), "fake-gcp-creds")
251 if err != nil {
252 t.Fatal(err)
253 }
254 if err := os.WriteFile(f.Name(), jsonCred, 0o666); err != nil {
255 t.Fatal(err)
256 }
257
258 t.Setenv(envVar, f.Name())
259 return func() {
260 t.Log("fake gcp default credentials done")
261 }
262}
263
264// newGCPRecordDialOptions return grpc.DialOptions that are to be appended to a
265// GRPC dial request. These options allow a recorder to intercept RPCs and save

Callers 10

TestOpenBucketFromURLFunction · 0.92
TestOpenKeeperFunction · 0.92
TestOpenTopicFromURLFunction · 0.92
TestOpenTopicFromURLFunction · 0.92
TestOpenVariableFunction · 0.92
TestOpenVariableFunction · 0.92

Calls 2

NameMethod · 0.65
LogMethod · 0.65

Tested by 10

TestOpenBucketFromURLFunction · 0.74
TestOpenKeeperFunction · 0.74
TestOpenTopicFromURLFunction · 0.74
TestOpenTopicFromURLFunction · 0.74
TestOpenVariableFunction · 0.74
TestOpenVariableFunction · 0.74