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

Method TestSetUniverseDomainNonDefault

xds/googledirectpath/googlec2p_test.go:379–474  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

377}
378
379func (s) TestSetUniverseDomainNonDefault(t *testing.T) {
380 replaceResolvers(t)
381 simulateRunningOnGCE(t, true)
382 useCleanUniverseDomain(t)
383 builder := resolver.Get(c2pScheme)
384
385 // Override the zone returned by the metadata server.
386 oldGetZone := getZone
387 getZone = func(time.Duration) string { return "test-zone" }
388 defer func() { getZone = oldGetZone }()
389
390 // Override IPv6 capability returned by the metadata server.
391 oldGetIPv6Capability := getIPv6Capable
392 getIPv6Capable = func(time.Duration) bool { return false }
393 defer func() { getIPv6Capable = oldGetIPv6Capability }()
394
395 // Override the random func used in the node ID.
396 origRandInd := randInt
397 randInt = func() int { return 666 }
398 defer func() { randInt = origRandInd }()
399
400 // Set the universe domain
401 testUniverseDomain := "test-universe-domain.test"
402 if err := SetUniverseDomain(testUniverseDomain); err != nil {
403 t.Fatalf("SetUniverseDomain(%s) failed: %v", testUniverseDomain, err)
404 }
405
406 // Now set universe domain to something different, it should fail
407 domain := "test-universe-domain-2.test"
408 err := SetUniverseDomain(domain)
409 wantErr := "already set"
410 if err == nil || !strings.Contains(err.Error(), wantErr) {
411 t.Fatalf("googlec2p.SetUniverseDomain(%s) returned error: %v, want: %v", domain, err, wantErr)
412 }
413
414 // Now explicitly set universe domain to the default, it should also fail
415 domain = "googleapis.com"
416 err = SetUniverseDomain(domain)
417 wantErr = "already set"
418 if err == nil || !strings.Contains(err.Error(), wantErr) {
419 t.Fatalf("googlec2p.SetUniverseDomain(%s) returned error: %v, want: %v", domain, err, wantErr)
420 }
421
422 // Now set universe domain to the original value, it should work
423 if err := SetUniverseDomain(testUniverseDomain); err != nil {
424 t.Fatalf("googlec2p.SetUniverseDomain(%s) failed: %v", testUniverseDomain, err)
425 }
426
427 // Override xDS client pool.
428 oldXdsClientPool := xdsClientPool
429 xdsClientPool = xdsclient.NewPool(nil)
430 defer func() { xdsClientPool = oldXdsClientPool }()
431
432 // Build the google-c2p resolver.
433 target := resolver.Target{URL: url.URL{Scheme: c2pScheme, Path: "test-path"}}
434 r, err := builder.Build(target, nil, resolver.BuildOptions{})
435 if err != nil {
436 t.Fatalf("failed to build resolver: %v", err)

Callers

nothing calls this directly

Calls 13

StringMethod · 0.95
GetFunction · 0.92
NewPoolFunction · 0.92
replaceResolversFunction · 0.85
simulateRunningOnGCEFunction · 0.85
useCleanUniverseDomainFunction · 0.85
SetUniverseDomainFunction · 0.85
bootstrapConfigFunction · 0.85
FatalfMethod · 0.65
ErrorMethod · 0.65
BuildMethod · 0.65

Tested by

no test coverage detected