Skip to content

Commit

Permalink
[federation_target_parsing] always set target
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Nov 8, 2021
1 parent 4480203 commit 27f50c7
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions xds/internal/resolver/xds_resolver_test.go
Expand Up @@ -229,7 +229,7 @@ func (s) TestResolverBuilder_xdsCredsBootstrapMismatch(t *testing.T) {

type setupOpts struct {
bootstrapC *bootstrap.Config
target *resolver.Target
target resolver.Target
}

func testSetup(t *testing.T, opts setupOpts) (*xdsResolver, *fakeclient.Client, *testClientConn, func()) {
Expand All @@ -253,18 +253,13 @@ func testSetup(t *testing.T, opts setupOpts) (*xdsResolver, *fakeclient.Client,
}
newXDSClient = oldClientMaker
}

builder := resolver.Get(xdsScheme)
if builder == nil {
t.Fatalf("resolver.Get(%v) returned nil", xdsScheme)
}

tcc := newTestClientConn()
tgt := target
if opts.target != nil {
tgt = *opts.target
}
r, err := builder.Build(tgt, tcc, resolver.BuildOptions{})
r, err := builder.Build(opts.target, tcc, resolver.BuildOptions{})
if err != nil {
t.Fatalf("builder.Build(%v) returned err: %v", target, err)
}
Expand Down Expand Up @@ -311,15 +306,15 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
tests := []struct {
name string
bc *bootstrap.Config
target *resolver.Target
target resolver.Target
want string
}{
{
name: "default %s old style",
bc: &bootstrap.Config{
ClientDefaultListenerResourceNameTemplate: "%s",
},
target: &resolver.Target{
target: resolver.Target{
URL: url.URL{Path: "/" + targetStr},
},
want: targetStr,
Expand All @@ -329,7 +324,7 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
bc: &bootstrap.Config{
ClientDefaultListenerResourceNameTemplate: "/path/to/%s",
},
target: &resolver.Target{
target: resolver.Target{
URL: url.URL{Path: "/" + targetStr},
},
want: "/path/to/" + targetStr,
Expand All @@ -340,7 +335,7 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
ClientDefaultListenerResourceNameTemplate: "xdstp://authority.com/%s",
Authorities: nil,
},
target: &resolver.Target{
target: resolver.Target{
URL: url.URL{Path: "/0.0.0.0:8080"},
},
want: "xdstp://authority.com/0.0.0.0:8080",
Expand All @@ -351,7 +346,7 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
ClientDefaultListenerResourceNameTemplate: "xdstp://authority.com/%s",
Authorities: nil,
},
target: &resolver.Target{
target: resolver.Target{
URL: url.URL{Path: "/[::1]:8080"},
},
want: "xdstp://authority.com/%5B::1%5D:8080",
Expand All @@ -366,7 +361,7 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
},
},
},
target: &resolver.Target{
target: resolver.Target{
URL: url.URL{
Host: "test-authority",
Path: "/" + targetStr,
Expand Down Expand Up @@ -394,7 +389,7 @@ func (s) TestXDSResolverResourceNameToWatch(t *testing.T) {
// TestXDSResolverWatchCallbackAfterClose tests the case where a service update
// from the underlying xdsClient is received after the resolver is closed.
func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer cancel()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
Expand Down Expand Up @@ -423,7 +418,7 @@ func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) {
// TestXDSResolverCloseClosesXDSClient tests that the XDS resolver's Close
// method closes the XDS client.
func (s) TestXDSResolverCloseClosesXDSClient(t *testing.T) {
xdsR, xdsC, _, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, _, cancel := testSetup(t, setupOpts{target: target})
defer cancel()
xdsR.Close()
if !xdsC.Closed.HasFired() {
Expand All @@ -434,7 +429,7 @@ func (s) TestXDSResolverCloseClosesXDSClient(t *testing.T) {
// TestXDSResolverBadServiceUpdate tests the case the xdsClient returns a bad
// service update.
func (s) TestXDSResolverBadServiceUpdate(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand All @@ -457,7 +452,7 @@ func (s) TestXDSResolverBadServiceUpdate(t *testing.T) {
// TestXDSResolverGoodServiceUpdate tests the happy case where the resolver
// gets a good service update from the xdsClient.
func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -593,7 +588,7 @@ func (s) TestXDSResolverRequestHash(t *testing.T) {
env.RingHashSupport = true
defer func() { env.RingHashSupport = oldRH }()

xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -650,7 +645,7 @@ func (s) TestXDSResolverRequestHash(t *testing.T) {
// TestXDSResolverRemovedWithRPCs tests the case where a config selector sends
// an empty update to the resolver after the resource is removed.
func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer cancel()
defer xdsR.Close()

Expand Down Expand Up @@ -707,7 +702,7 @@ func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) {
// TestXDSResolverRemovedResource tests for proper behavior after a resource is
// removed.
func (s) TestXDSResolverRemovedResource(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer cancel()
defer xdsR.Close()

Expand Down Expand Up @@ -812,7 +807,7 @@ func (s) TestXDSResolverRemovedResource(t *testing.T) {
}

func (s) TestXDSResolverWRR(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -869,7 +864,7 @@ func (s) TestXDSResolverWRR(t *testing.T) {
}

func (s) TestXDSResolverMaxStreamDuration(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -959,7 +954,7 @@ func (s) TestXDSResolverMaxStreamDuration(t *testing.T) {
// TestXDSResolverDelayedOnCommitted tests that clusters remain in service
// config if RPCs are in flight.
func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -1105,7 +1100,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) {
// TestXDSResolverUpdates tests the cases where the resolver gets a good update
// after an error, and an error after the good update.
func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -1156,7 +1151,7 @@ func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) {
// a ResourceNotFoundError. It should generate a service config picking
// weighted_target, but no child balancers.
func (s) TestXDSResolverResourceNotFoundError(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -1199,7 +1194,7 @@ func (s) TestXDSResolverResourceNotFoundError(t *testing.T) {
//
// This test case also makes sure the resolver doesn't panic.
func (s) TestXDSResolverMultipleLDSUpdates(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down Expand Up @@ -1371,7 +1366,7 @@ func (s) TestXDSResolverHTTPFilters(t *testing.T) {

for i, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{})
xdsR, xdsC, tcc, cancel := testSetup(t, setupOpts{target: target})
defer xdsR.Close()
defer cancel()

Expand Down

0 comments on commit 27f50c7

Please sign in to comment.