FakeGCPDefaultCredentials sets up the environment with fake GCP credentials. It returns a cleanup function.
(t *testing.T)
| 242 | // FakeGCPDefaultCredentials sets up the environment with fake GCP credentials. |
| 243 | // It returns a cleanup function. |
| 244 | func 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 |