MCPcopy
hub / github.com/grpc/grpc-go / TestBothConfigEnvVarsSet

Method TestBothConfigEnvVarsSet

gcp/observability/observability_test.go:279–328  ·  view source on GitHub ↗

TestBothConfigEnvVarsSet tests the scenario where both configuration environment variables are set. The file system environment variable should take precedence, and an error should return in the case of the file system configuration being invalid, even if the direct configuration environment variabl

(t *testing.T)

Source from the content-addressed store, hash-verified

277// configuration being invalid, even if the direct configuration environment
278// variable is set and valid.
279func (s) TestBothConfigEnvVarsSet(t *testing.T) {
280 invalidConfig := &config{
281 ProjectID: "fake",
282 CloudLogging: &cloudLogging{
283 ClientRPCEvents: []clientRPCEvents{
284 {
285 Methods: []string{":-)"},
286 MaxMetadataBytes: 30,
287 MaxMessageBytes: 30,
288 },
289 },
290 },
291 }
292 invalidConfigJSON, err := json.Marshal(invalidConfig)
293 if err != nil {
294 t.Fatalf("failed to convert config to JSON: %v", err)
295 }
296 cleanup, err := createTmpConfigInFileSystem(string(invalidConfigJSON))
297 defer cleanup()
298 if err != nil {
299 t.Fatalf("failed to create config in file system: %v", err)
300 }
301 // This configuration should be ignored, as precedence 2.
302 validConfig := &config{
303 ProjectID: "fake",
304 CloudLogging: &cloudLogging{
305 ClientRPCEvents: []clientRPCEvents{
306 {
307 Methods: []string{"*"},
308 MaxMetadataBytes: 30,
309 MaxMessageBytes: 30,
310 },
311 },
312 },
313 }
314 validConfigJSON, err := json.Marshal(validConfig)
315 if err != nil {
316 t.Fatalf("failed to convert config to JSON: %v", err)
317 }
318 oldObservabilityConfig := envconfig.ObservabilityConfig
319 envconfig.ObservabilityConfig = string(validConfigJSON)
320 defer func() {
321 envconfig.ObservabilityConfig = oldObservabilityConfig
322 }()
323 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
324 defer cancel()
325 if err := Start(ctx); err == nil {
326 t.Fatalf("Invalid patterns not triggering error")
327 }
328}
329
330// TestErrInFileSystemEnvVar tests the scenario where an observability
331// configuration is specified with environment variable that specifies a

Callers

nothing calls this directly

Calls 4

StartFunction · 0.85
MarshalMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected