From e7c14e455ac9bb08e9b4e94cad865474db328ede Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Fri, 10 Sep 2021 10:48:16 -0700 Subject: [PATCH] rename to XXXUpdateErrTuple --- xds/internal/xdsclient/callback.go | 8 +- xds/internal/xdsclient/cds_test.go | 12 +-- xds/internal/xdsclient/client.go | 8 +- xds/internal/xdsclient/client_test.go | 14 +-- xds/internal/xdsclient/dump_test.go | 24 ++--- xds/internal/xdsclient/eds_test.go | 8 +- xds/internal/xdsclient/lds_test.go | 102 +++++++++--------- xds/internal/xdsclient/rds_test.go | 10 +- xds/internal/xdsclient/v2/cds_test.go | 6 +- xds/internal/xdsclient/v2/client_test.go | 26 ++--- xds/internal/xdsclient/v2/eds_test.go | 6 +- xds/internal/xdsclient/v2/lds_test.go | 12 +-- xds/internal/xdsclient/v2/rds_test.go | 8 +- .../xdsclient/watchers_cluster_test.go | 54 +++++----- .../xdsclient/watchers_endpoints_test.go | 38 +++---- .../xdsclient/watchers_listener_test.go | 46 ++++---- xds/internal/xdsclient/watchers_route_test.go | 36 +++---- xds/internal/xdsclient/xds.go | 64 ++++++----- 18 files changed, 245 insertions(+), 237 deletions(-) diff --git a/xds/internal/xdsclient/callback.go b/xds/internal/xdsclient/callback.go index c1e73ed19a31..0374389fbca1 100644 --- a/xds/internal/xdsclient/callback.go +++ b/xds/internal/xdsclient/callback.go @@ -76,7 +76,7 @@ func (c *clientImpl) callCallback(wiu *watcherInfoWithUpdate) { // // A response can contain multiple resources. They will be parsed and put in a // map from resource name to the resource content. -func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErr, metadata UpdateMetadata) { +func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErrTuple, metadata UpdateMetadata) { c.mu.Lock() defer c.mu.Unlock() @@ -141,7 +141,7 @@ func (c *clientImpl) NewListeners(updates map[string]ListenerUpdateErr, metadata // // A response can contain multiple resources. They will be parsed and put in a // map from resource name to the resource content. -func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErr, metadata UpdateMetadata) { +func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErrTuple, metadata UpdateMetadata) { c.mu.Lock() defer c.mu.Unlock() @@ -190,7 +190,7 @@ func (c *clientImpl) NewRouteConfigs(updates map[string]RouteConfigUpdateErr, me // // A response can contain multiple resources. They will be parsed and put in a // map from resource name to the resource content. -func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErr, metadata UpdateMetadata) { +func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErrTuple, metadata UpdateMetadata) { c.mu.Lock() defer c.mu.Unlock() @@ -257,7 +257,7 @@ func (c *clientImpl) NewClusters(updates map[string]ClusterUpdateErr, metadata U // // A response can contain multiple resources. They will be parsed and put in a // map from resource name to the resource content. -func (c *clientImpl) NewEndpoints(updates map[string]EndpointsUpdateErr, metadata UpdateMetadata) { +func (c *clientImpl) NewEndpoints(updates map[string]EndpointsUpdateErrTuple, metadata UpdateMetadata) { c.mu.Lock() defer c.mu.Unlock() diff --git a/xds/internal/xdsclient/cds_test.go b/xds/internal/xdsclient/cds_test.go index b0b8febf0712..f38e389da529 100644 --- a/xds/internal/xdsclient/cds_test.go +++ b/xds/internal/xdsclient/cds_test.go @@ -945,7 +945,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { tests := []struct { name string resources []*anypb.Any - wantUpdate map[string]ClusterUpdateErr + wantUpdate map[string]ClusterUpdateErrTuple wantMD UpdateMetadata wantErr bool }{ @@ -988,7 +988,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_STATIC}, }), }, - wantUpdate: map[string]ClusterUpdateErr{ + wantUpdate: map[string]ClusterUpdateErrTuple{ "test": {Err: cmpopts.AnyError}, }, wantMD: UpdateMetadata{ @@ -1004,7 +1004,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { { name: "v2 cluster", resources: []*anypb.Any{v2ClusterAny}, - wantUpdate: map[string]ClusterUpdateErr{ + wantUpdate: map[string]ClusterUpdateErrTuple{ v2ClusterName: {Update: ClusterUpdate{ ClusterName: v2ClusterName, EDSServiceName: v2Service, EnableLRS: true, @@ -1019,7 +1019,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { { name: "v3 cluster", resources: []*anypb.Any{v3ClusterAny}, - wantUpdate: map[string]ClusterUpdateErr{ + wantUpdate: map[string]ClusterUpdateErrTuple{ v3ClusterName: {Update: ClusterUpdate{ ClusterName: v3ClusterName, EDSServiceName: v3Service, EnableLRS: true, @@ -1034,7 +1034,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { { name: "multiple clusters", resources: []*anypb.Any{v2ClusterAny, v3ClusterAny}, - wantUpdate: map[string]ClusterUpdateErr{ + wantUpdate: map[string]ClusterUpdateErrTuple{ v2ClusterName: {Update: ClusterUpdate{ ClusterName: v2ClusterName, EDSServiceName: v2Service, EnableLRS: true, @@ -1063,7 +1063,7 @@ func (s) TestUnmarshalCluster(t *testing.T) { }), v3ClusterAny, }, - wantUpdate: map[string]ClusterUpdateErr{ + wantUpdate: map[string]ClusterUpdateErrTuple{ v2ClusterName: {Update: ClusterUpdate{ ClusterName: v2ClusterName, EDSServiceName: v2Service, EnableLRS: true, diff --git a/xds/internal/xdsclient/client.go b/xds/internal/xdsclient/client.go index 85a9097401ca..2aa5b1723135 100644 --- a/xds/internal/xdsclient/client.go +++ b/xds/internal/xdsclient/client.go @@ -134,14 +134,14 @@ type loadReportingOptions struct { // resource updates from an APIClient for a specific version. type UpdateHandler interface { // NewListeners handles updates to xDS listener resources. - NewListeners(map[string]ListenerUpdateErr, UpdateMetadata) + NewListeners(map[string]ListenerUpdateErrTuple, UpdateMetadata) // NewRouteConfigs handles updates to xDS RouteConfiguration resources. - NewRouteConfigs(map[string]RouteConfigUpdateErr, UpdateMetadata) + NewRouteConfigs(map[string]RouteConfigUpdateErrTuple, UpdateMetadata) // NewClusters handles updates to xDS Cluster resources. - NewClusters(map[string]ClusterUpdateErr, UpdateMetadata) + NewClusters(map[string]ClusterUpdateErrTuple, UpdateMetadata) // NewEndpoints handles updates to xDS ClusterLoadAssignment (or tersely // referred to as Endpoints) resources. - NewEndpoints(map[string]EndpointsUpdateErr, UpdateMetadata) + NewEndpoints(map[string]EndpointsUpdateErrTuple, UpdateMetadata) // NewConnectionError handles connection errors from the xDS stream. The // error will be reported to all the resource watchers. NewConnectionError(err error) diff --git a/xds/internal/xdsclient/client_test.go b/xds/internal/xdsclient/client_test.go index b224e7839fb0..d8e942196311 100644 --- a/xds/internal/xdsclient/client_test.go +++ b/xds/internal/xdsclient/client_test.go @@ -162,7 +162,7 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) { clusterUpdateCh := testutils.NewChannel() firstTime := true client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) // Calls another watch inline, to ensure there's deadlock. client.WatchCluster("another-random-name", func(ClusterUpdate, error) {}) @@ -176,13 +176,13 @@ func (s) TestWatchCallAnotherWatch(t *testing.T) { } wantUpdate := ClusterUpdate{ClusterName: testEDSName} - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } wantUpdate2 := ClusterUpdate{ClusterName: testEDSName + "2"} - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate2}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate2}}, UpdateMetadata{}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate2, nil); err != nil { t.Fatal(err) } @@ -193,7 +193,7 @@ func verifyListenerUpdate(ctx context.Context, updateCh *testutils.Channel, want if err != nil { return fmt.Errorf("timeout when waiting for listener update: %v", err) } - gotUpdate := u.(ListenerUpdateErr) + gotUpdate := u.(ListenerUpdateErrTuple) if wantErr != nil { if gotUpdate.Err != wantErr { return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr) @@ -211,7 +211,7 @@ func verifyRouteConfigUpdate(ctx context.Context, updateCh *testutils.Channel, w if err != nil { return fmt.Errorf("timeout when waiting for route configuration update: %v", err) } - gotUpdate := u.(RouteConfigUpdateErr) + gotUpdate := u.(RouteConfigUpdateErrTuple) if wantErr != nil { if gotUpdate.Err != wantErr { return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr) @@ -229,7 +229,7 @@ func verifyClusterUpdate(ctx context.Context, updateCh *testutils.Channel, wantU if err != nil { return fmt.Errorf("timeout when waiting for cluster update: %v", err) } - gotUpdate := u.(ClusterUpdateErr) + gotUpdate := u.(ClusterUpdateErrTuple) if wantErr != nil { if gotUpdate.Err != wantErr { return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr) @@ -247,7 +247,7 @@ func verifyEndpointsUpdate(ctx context.Context, updateCh *testutils.Channel, wan if err != nil { return fmt.Errorf("timeout when waiting for endpoints update: %v", err) } - gotUpdate := u.(EndpointsUpdateErr) + gotUpdate := u.(EndpointsUpdateErrTuple) if wantErr != nil { if gotUpdate.Err != wantErr { return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr) diff --git a/xds/internal/xdsclient/dump_test.go b/xds/internal/xdsclient/dump_test.go index 125c65e6bc7a..d03479ca4ade 100644 --- a/xds/internal/xdsclient/dump_test.go +++ b/xds/internal/xdsclient/dump_test.go @@ -101,10 +101,10 @@ func (s) TestLDSConfigDump(t *testing.T) { t.Fatalf(err.Error()) } - update0 := make(map[string]xdsclient.ListenerUpdateErr) + update0 := make(map[string]xdsclient.ListenerUpdateErrTuple) want0 := make(map[string]xdsclient.UpdateWithMD) for n, r := range listenerRaws { - update0[n] = xdsclient.ListenerUpdateErr{Update: xdsclient.ListenerUpdate{Raw: r}} + update0[n] = xdsclient.ListenerUpdateErrTuple{Update: xdsclient.ListenerUpdate{Raw: r}} want0[n] = xdsclient.UpdateWithMD{ MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion}, Raw: r, @@ -120,7 +120,7 @@ func (s) TestLDSConfigDump(t *testing.T) { const nackVersion = "lds-version-nack" var nackErr = fmt.Errorf("lds nack error") updateHandler.NewListeners( - map[string]xdsclient.ListenerUpdateErr{ + map[string]xdsclient.ListenerUpdateErrTuple{ ldsTargets[0]: {Err: nackErr}, ldsTargets[1]: {Update: xdsclient.ListenerUpdate{Raw: listenerRaws[ldsTargets[1]]}}, }, @@ -215,10 +215,10 @@ func (s) TestRDSConfigDump(t *testing.T) { t.Fatalf(err.Error()) } - update0 := make(map[string]xdsclient.RouteConfigUpdateErr) + update0 := make(map[string]xdsclient.RouteConfigUpdateErrTuple) want0 := make(map[string]xdsclient.UpdateWithMD) for n, r := range routeRaws { - update0[n] = xdsclient.RouteConfigUpdateErr{Update: xdsclient.RouteConfigUpdate{Raw: r}} + update0[n] = xdsclient.RouteConfigUpdateErrTuple{Update: xdsclient.RouteConfigUpdate{Raw: r}} want0[n] = xdsclient.UpdateWithMD{ MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion}, Raw: r, @@ -234,7 +234,7 @@ func (s) TestRDSConfigDump(t *testing.T) { const nackVersion = "rds-version-nack" var nackErr = fmt.Errorf("rds nack error") updateHandler.NewRouteConfigs( - map[string]xdsclient.RouteConfigUpdateErr{ + map[string]xdsclient.RouteConfigUpdateErrTuple{ rdsTargets[0]: {Err: nackErr}, rdsTargets[1]: {Update: xdsclient.RouteConfigUpdate{Raw: routeRaws[rdsTargets[1]]}}, }, @@ -329,10 +329,10 @@ func (s) TestCDSConfigDump(t *testing.T) { t.Fatalf(err.Error()) } - update0 := make(map[string]xdsclient.ClusterUpdateErr) + update0 := make(map[string]xdsclient.ClusterUpdateErrTuple) want0 := make(map[string]xdsclient.UpdateWithMD) for n, r := range clusterRaws { - update0[n] = xdsclient.ClusterUpdateErr{Update: xdsclient.ClusterUpdate{Raw: r}} + update0[n] = xdsclient.ClusterUpdateErrTuple{Update: xdsclient.ClusterUpdate{Raw: r}} want0[n] = xdsclient.UpdateWithMD{ MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion}, Raw: r, @@ -348,7 +348,7 @@ func (s) TestCDSConfigDump(t *testing.T) { const nackVersion = "cds-version-nack" var nackErr = fmt.Errorf("cds nack error") updateHandler.NewClusters( - map[string]xdsclient.ClusterUpdateErr{ + map[string]xdsclient.ClusterUpdateErrTuple{ cdsTargets[0]: {Err: nackErr}, cdsTargets[1]: {Update: xdsclient.ClusterUpdate{Raw: clusterRaws[cdsTargets[1]]}}, }, @@ -429,10 +429,10 @@ func (s) TestEDSConfigDump(t *testing.T) { t.Fatalf(err.Error()) } - update0 := make(map[string]xdsclient.EndpointsUpdateErr) + update0 := make(map[string]xdsclient.EndpointsUpdateErrTuple) want0 := make(map[string]xdsclient.UpdateWithMD) for n, r := range endpointRaws { - update0[n] = xdsclient.EndpointsUpdateErr{Update: xdsclient.EndpointsUpdate{Raw: r}} + update0[n] = xdsclient.EndpointsUpdateErrTuple{Update: xdsclient.EndpointsUpdate{Raw: r}} want0[n] = xdsclient.UpdateWithMD{ MD: xdsclient.UpdateMetadata{Status: xdsclient.ServiceStatusACKed, Version: testVersion}, Raw: r, @@ -448,7 +448,7 @@ func (s) TestEDSConfigDump(t *testing.T) { const nackVersion = "eds-version-nack" var nackErr = fmt.Errorf("eds nack error") updateHandler.NewEndpoints( - map[string]xdsclient.EndpointsUpdateErr{ + map[string]xdsclient.EndpointsUpdateErrTuple{ edsTargets[0]: {Err: nackErr}, edsTargets[1]: {Update: xdsclient.EndpointsUpdate{Raw: endpointRaws[edsTargets[1]]}}, }, diff --git a/xds/internal/xdsclient/eds_test.go b/xds/internal/xdsclient/eds_test.go index 1442c6bc7bd3..d09134f58206 100644 --- a/xds/internal/xdsclient/eds_test.go +++ b/xds/internal/xdsclient/eds_test.go @@ -138,7 +138,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) { tests := []struct { name string resources []*anypb.Any - wantUpdate map[string]EndpointsUpdateErr + wantUpdate map[string]EndpointsUpdateErrTuple wantMD UpdateMetadata wantErr bool }{ @@ -181,7 +181,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) { clab0.addLocality("locality-2", 1, 2, []string{"addr2:159"}, nil) return clab0.Build() }())}, - wantUpdate: map[string]EndpointsUpdateErr{"test": {Err: cmpopts.AnyError}}, + wantUpdate: map[string]EndpointsUpdateErrTuple{"test": {Err: cmpopts.AnyError}}, wantMD: UpdateMetadata{ Status: ServiceStatusNACKed, Version: testVersion, @@ -195,7 +195,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) { { name: "v3 endpoints", resources: []*anypb.Any{v3EndpointsAny}, - wantUpdate: map[string]EndpointsUpdateErr{ + wantUpdate: map[string]EndpointsUpdateErrTuple{ "test": {Update: EndpointsUpdate{ Drops: nil, Localities: []Locality{ @@ -240,7 +240,7 @@ func (s) TestUnmarshalEndpoints(t *testing.T) { return clab0.Build() }()), }, - wantUpdate: map[string]EndpointsUpdateErr{ + wantUpdate: map[string]EndpointsUpdateErrTuple{ "test": {Update: EndpointsUpdate{ Drops: nil, Localities: []Locality{ diff --git a/xds/internal/xdsclient/lds_test.go b/xds/internal/xdsclient/lds_test.go index aad1019683d2..56a51e46eb6d 100644 --- a/xds/internal/xdsclient/lds_test.go +++ b/xds/internal/xdsclient/lds_test.go @@ -185,7 +185,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { tests := []struct { name string resources []*anypb.Any - wantUpdate map[string]ListenerUpdateErr + wantUpdate map[string]ListenerUpdateErrTuple wantMD UpdateMetadata wantErr bool }{ @@ -215,7 +215,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }(), }, }, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, @@ -227,7 +227,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { ApiListener: testutils.MarshalAny(&v2xdspb.Listener{}), }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, @@ -243,7 +243,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }), }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, @@ -257,7 +257,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }), }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, @@ -280,7 +280,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }), }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, @@ -294,7 +294,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with no filters", resources: []*anypb.Any{v3LisWithFilters()}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: routerFilterList, Raw: v3LisWithFilters()}}, }, wantMD: UpdateMetadata{ @@ -323,14 +323,14 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }), }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with custom filter", resources: []*anypb.Any{v3LisWithFilters(customFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: []HTTPFilter{ @@ -352,7 +352,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with custom filter in typed struct", resources: []*anypb.Any{v3LisWithFilters(typedStructFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: []HTTPFilter{ @@ -374,7 +374,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with optional custom filter", resources: []*anypb.Any{v3LisWithFilters(customOptionalFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: []HTTPFilter{ @@ -396,14 +396,14 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with two filters with same name", resources: []*anypb.Any{v3LisWithFilters(customFilter, customFilter)}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with two filters - same type different name", resources: []*anypb.Any{v3LisWithFilters(customFilter, customFilter2)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: []HTTPFilter{{ @@ -428,14 +428,14 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with server-only filter", resources: []*anypb.Any{v3LisWithFilters(serverOnlyCustomFilter)}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with optional server-only filter", resources: []*anypb.Any{v3LisWithFilters(serverOnlyOptionalCustomFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, @@ -451,7 +451,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with client-only filter", resources: []*anypb.Any{v3LisWithFilters(clientOnlyCustomFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: []HTTPFilter{ @@ -472,28 +472,28 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 with err filter", resources: []*anypb.Any{v3LisWithFilters(errFilter)}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with optional err filter", resources: []*anypb.Any{v3LisWithFilters(errOptionalFilter)}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with unknown filter", resources: []*anypb.Any{v3LisWithFilters(unknownFilter)}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: true, }, { name: "v3 with unknown filter (optional)", resources: []*anypb.Any{v3LisWithFilters(unknownOptionalFilter)}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, @@ -509,7 +509,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v2 listener resource", resources: []*anypb.Any{v2Lis}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v2LDSTarget: {Update: ListenerUpdate{RouteConfigName: v2RouteConfigName, Raw: v2Lis}}, }, wantMD: UpdateMetadata{ @@ -520,7 +520,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 listener resource", resources: []*anypb.Any{v3LisWithFilters()}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, HTTPFilters: routerFilterList, Raw: v3LisWithFilters()}}, }, wantMD: UpdateMetadata{ @@ -531,7 +531,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "v3 listener with inline route configuration", resources: []*anypb.Any{v3LisWithInlineRoute}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ InlineRouteConfig: &RouteConfigUpdate{ VirtualHosts: []*VirtualHost{{ @@ -551,7 +551,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { { name: "multiple listener resources", resources: []*anypb.Any{v2Lis, v3LisWithFilters()}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v2LDSTarget: {Update: ListenerUpdate{RouteConfigName: v2RouteConfigName, Raw: v2Lis}}, v3LDSTarget: {Update: ListenerUpdate{RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, Raw: v3LisWithFilters(), HTTPFilters: routerFilterList}}, }, @@ -574,7 +574,7 @@ func (s) TestUnmarshalListener_ClientSide(t *testing.T) { }}), v3LisWithFilters(), }, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v2LDSTarget: {Update: ListenerUpdate{RouteConfigName: v2RouteConfigName, Raw: v2Lis}}, v3LDSTarget: {Update: ListenerUpdate{RouteConfigName: v3RouteConfigName, MaxStreamDuration: time.Second, Raw: v3LisWithFilters(), HTTPFilters: routerFilterList}}, "bad": {Err: cmpopts.AnyError}, @@ -766,7 +766,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { tests := []struct { name string resources []*anypb.Any - wantUpdate map[string]ListenerUpdateErr + wantUpdate map[string]ListenerUpdateErrTuple wantMD UpdateMetadata wantErr string }{ @@ -778,7 +778,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { {Name: "listener-filter-1"}, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "unsupported field 'listener_filters'", }, @@ -788,14 +788,14 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { Name: v3LDSTarget, UseOriginalDst: &wrapperspb.BoolValue{Value: true}, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "unsupported field 'use_original_dst'", }, { name: "no address field", resources: []*anypb.Any{testutils.MarshalAny(&v3listenerpb.Listener{Name: v3LDSTarget})}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "no address field in LDS response", }, @@ -805,7 +805,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { Name: v3LDSTarget, Address: &v3corepb.Address{}, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "no socket_address field in LDS response", }, @@ -821,7 +821,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "no supported filter chains and no default filter chain", }, @@ -836,7 +836,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "missing HttpConnectionManager filter", }, @@ -858,7 +858,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "missing name field in filter", }, @@ -897,7 +897,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "duplicate filter name", }, @@ -924,7 +924,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "http filters list is empty", }, @@ -952,7 +952,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "is a terminal filter but it is not last in the filter chain", }, @@ -980,7 +980,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "is not a terminal filter", }, @@ -1001,7 +1001,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "unsupported config_type", }, @@ -1025,7 +1025,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "multiple filter chains with overlapping matching rules are defined", }, @@ -1048,7 +1048,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "unsupported network filter", }, @@ -1074,7 +1074,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "failed unmarshaling of network filter", }, @@ -1093,7 +1093,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "transport_socket field has unexpected name", }, @@ -1115,7 +1115,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "transport_socket field has unexpected typeURL", }, @@ -1140,7 +1140,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "failed to unmarshal DownstreamTlsContext in LDS response", }, @@ -1162,7 +1162,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "DownstreamTlsContext in LDS response does not contain a CommonTlsContext", }, @@ -1192,14 +1192,14 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "validation context contains unexpected type", }, { name: "empty transport socket", resources: []*anypb.Any{listenerEmptyTransportSocket}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ InboundListenerCfg: &InboundListenerConfig{ Address: "0.0.0.0", @@ -1259,7 +1259,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "security configuration on the server-side does not contain root certificate provider instance name, but require_client_cert field is set", }, @@ -1283,14 +1283,14 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { }, }, })}, - wantUpdate: map[string]ListenerUpdateErr{v3LDSTarget: {Err: cmpopts.AnyError}}, + wantUpdate: map[string]ListenerUpdateErrTuple{v3LDSTarget: {Err: cmpopts.AnyError}}, wantMD: errMD, wantErr: "security configuration on the server-side does not contain identity certificate provider instance name", }, { name: "happy case with no validation context", resources: []*anypb.Any{listenerNoValidationContext}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ InboundListenerCfg: &InboundListenerConfig{ Address: "0.0.0.0", @@ -1339,7 +1339,7 @@ func (s) TestUnmarshalListener_ServerSide(t *testing.T) { { name: "happy case with validation context provider instance", resources: []*anypb.Any{listenerWithValidationContext}, - wantUpdate: map[string]ListenerUpdateErr{ + wantUpdate: map[string]ListenerUpdateErrTuple{ v3LDSTarget: {Update: ListenerUpdate{ InboundListenerCfg: &InboundListenerConfig{ Address: "0.0.0.0", diff --git a/xds/internal/xdsclient/rds_test.go b/xds/internal/xdsclient/rds_test.go index 58263628613e..6d1f8588f2df 100644 --- a/xds/internal/xdsclient/rds_test.go +++ b/xds/internal/xdsclient/rds_test.go @@ -668,7 +668,7 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { tests := []struct { name string resources []*anypb.Any - wantUpdate map[string]RouteConfigUpdateErr + wantUpdate map[string]RouteConfigUpdateErrTuple wantMD UpdateMetadata wantErr bool }{ @@ -713,7 +713,7 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { { name: "v2 routeConfig resource", resources: []*anypb.Any{v2RouteConfig}, - wantUpdate: map[string]RouteConfigUpdateErr{ + wantUpdate: map[string]RouteConfigUpdateErrTuple{ v2RouteConfigName: {Update: RouteConfigUpdate{ VirtualHosts: []*VirtualHost{ { @@ -740,7 +740,7 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { { name: "v3 routeConfig resource", resources: []*anypb.Any{v3RouteConfig}, - wantUpdate: map[string]RouteConfigUpdateErr{ + wantUpdate: map[string]RouteConfigUpdateErrTuple{ v3RouteConfigName: {Update: RouteConfigUpdate{ VirtualHosts: []*VirtualHost{ { @@ -767,7 +767,7 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { { name: "multiple routeConfig resources", resources: []*anypb.Any{v2RouteConfig, v3RouteConfig}, - wantUpdate: map[string]RouteConfigUpdateErr{ + wantUpdate: map[string]RouteConfigUpdateErrTuple{ v3RouteConfigName: {Update: RouteConfigUpdate{ VirtualHosts: []*VirtualHost{ { @@ -822,7 +822,7 @@ func (s) TestUnmarshalRouteConfig(t *testing.T) { }}}}}), v3RouteConfig, }, - wantUpdate: map[string]RouteConfigUpdateErr{ + wantUpdate: map[string]RouteConfigUpdateErrTuple{ v3RouteConfigName: {Update: RouteConfigUpdate{ VirtualHosts: []*VirtualHost{ { diff --git a/xds/internal/xdsclient/v2/cds_test.go b/xds/internal/xdsclient/v2/cds_test.go index b81e72b4f580..cef7563017c4 100644 --- a/xds/internal/xdsclient/v2/cds_test.go +++ b/xds/internal/xdsclient/v2/cds_test.go @@ -101,7 +101,7 @@ func (s) TestCDSHandleResponse(t *testing.T) { name string cdsResponse *xdspb.DiscoveryResponse wantErr bool - wantUpdate map[string]xdsclient.ClusterUpdateErr + wantUpdate map[string]xdsclient.ClusterUpdateErrTuple wantUpdateMD xdsclient.UpdateMetadata wantUpdateErr bool }{ @@ -149,7 +149,7 @@ func (s) TestCDSHandleResponse(t *testing.T) { name: "one-uninteresting-cluster", cdsResponse: goodCDSResponse2, wantErr: false, - wantUpdate: map[string]xdsclient.ClusterUpdateErr{ + wantUpdate: map[string]xdsclient.ClusterUpdateErrTuple{ goodClusterName2: {Update: xdsclient.ClusterUpdate{ClusterName: goodClusterName2, EDSServiceName: serviceName2, Raw: marshaledCluster2}}, }, wantUpdateMD: xdsclient.UpdateMetadata{ @@ -162,7 +162,7 @@ func (s) TestCDSHandleResponse(t *testing.T) { name: "one-good-cluster", cdsResponse: goodCDSResponse1, wantErr: false, - wantUpdate: map[string]xdsclient.ClusterUpdateErr{ + wantUpdate: map[string]xdsclient.ClusterUpdateErrTuple{ goodClusterName1: {Update: xdsclient.ClusterUpdate{ClusterName: goodClusterName1, EDSServiceName: serviceName1, EnableLRS: true, Raw: marshaledCluster1}}, }, wantUpdateMD: xdsclient.UpdateMetadata{ diff --git a/xds/internal/xdsclient/v2/client_test.go b/xds/internal/xdsclient/v2/client_test.go index f04aa8fbcc47..ed4322b0dc51 100644 --- a/xds/internal/xdsclient/v2/client_test.go +++ b/xds/internal/xdsclient/v2/client_test.go @@ -301,7 +301,7 @@ type testUpdateReceiver struct { f func(rType xdsclient.ResourceType, d map[string]interface{}, md xdsclient.UpdateMetadata) } -func (t *testUpdateReceiver) NewListeners(d map[string]xdsclient.ListenerUpdateErr, metadata xdsclient.UpdateMetadata) { +func (t *testUpdateReceiver) NewListeners(d map[string]xdsclient.ListenerUpdateErrTuple, metadata xdsclient.UpdateMetadata) { dd := make(map[string]interface{}) for k, v := range d { dd[k] = v @@ -309,7 +309,7 @@ func (t *testUpdateReceiver) NewListeners(d map[string]xdsclient.ListenerUpdateE t.newUpdate(xdsclient.ListenerResource, dd, metadata) } -func (t *testUpdateReceiver) NewRouteConfigs(d map[string]xdsclient.RouteConfigUpdateErr, metadata xdsclient.UpdateMetadata) { +func (t *testUpdateReceiver) NewRouteConfigs(d map[string]xdsclient.RouteConfigUpdateErrTuple, metadata xdsclient.UpdateMetadata) { dd := make(map[string]interface{}) for k, v := range d { dd[k] = v @@ -317,7 +317,7 @@ func (t *testUpdateReceiver) NewRouteConfigs(d map[string]xdsclient.RouteConfigU t.newUpdate(xdsclient.RouteConfigResource, dd, metadata) } -func (t *testUpdateReceiver) NewClusters(d map[string]xdsclient.ClusterUpdateErr, metadata xdsclient.UpdateMetadata) { +func (t *testUpdateReceiver) NewClusters(d map[string]xdsclient.ClusterUpdateErrTuple, metadata xdsclient.UpdateMetadata) { dd := make(map[string]interface{}) for k, v := range d { dd[k] = v @@ -325,7 +325,7 @@ func (t *testUpdateReceiver) NewClusters(d map[string]xdsclient.ClusterUpdateErr t.newUpdate(xdsclient.ClusterResource, dd, metadata) } -func (t *testUpdateReceiver) NewEndpoints(d map[string]xdsclient.EndpointsUpdateErr, metadata xdsclient.UpdateMetadata) { +func (t *testUpdateReceiver) NewEndpoints(d map[string]xdsclient.EndpointsUpdateErrTuple, metadata xdsclient.UpdateMetadata) { dd := make(map[string]interface{}) for k, v := range d { dd[k] = v @@ -363,27 +363,27 @@ func testWatchHandle(t *testing.T, test *watchHandleTestcase) { if rType == test.rType { switch test.rType { case xdsclient.ListenerResource: - dd := make(map[string]xdsclient.ListenerUpdateErr) + dd := make(map[string]xdsclient.ListenerUpdateErrTuple) for n, u := range d { - dd[n] = u.(xdsclient.ListenerUpdateErr) + dd[n] = u.(xdsclient.ListenerUpdateErrTuple) } gotUpdateCh.Send(updateErr{dd, md, nil}) case xdsclient.RouteConfigResource: - dd := make(map[string]xdsclient.RouteConfigUpdateErr) + dd := make(map[string]xdsclient.RouteConfigUpdateErrTuple) for n, u := range d { - dd[n] = u.(xdsclient.RouteConfigUpdateErr) + dd[n] = u.(xdsclient.RouteConfigUpdateErrTuple) } gotUpdateCh.Send(updateErr{dd, md, nil}) case xdsclient.ClusterResource: - dd := make(map[string]xdsclient.ClusterUpdateErr) + dd := make(map[string]xdsclient.ClusterUpdateErrTuple) for n, u := range d { - dd[n] = u.(xdsclient.ClusterUpdateErr) + dd[n] = u.(xdsclient.ClusterUpdateErrTuple) } gotUpdateCh.Send(updateErr{dd, md, nil}) case xdsclient.EndpointsResource: - dd := make(map[string]xdsclient.EndpointsUpdateErr) + dd := make(map[string]xdsclient.EndpointsUpdateErrTuple) for n, u := range d { - dd[n] = u.(xdsclient.EndpointsUpdateErr) + dd[n] = u.(xdsclient.EndpointsUpdateErrTuple) } gotUpdateCh.Send(updateErr{dd, md, nil}) } @@ -664,7 +664,7 @@ func (s) TestV2ClientWatchWithoutStream(t *testing.T) { if v, err := callbackCh.Receive(ctx); err != nil { t.Fatal("Timeout when expecting LDS update") - } else if _, ok := v.(xdsclient.ListenerUpdateErr); !ok { + } else if _, ok := v.(xdsclient.ListenerUpdateErrTuple); !ok { t.Fatalf("Expect an LDS update from watcher, got %v", v) } } diff --git a/xds/internal/xdsclient/v2/eds_test.go b/xds/internal/xdsclient/v2/eds_test.go index 04bddc12db7c..8176b6dfb93a 100644 --- a/xds/internal/xdsclient/v2/eds_test.go +++ b/xds/internal/xdsclient/v2/eds_test.go @@ -76,7 +76,7 @@ func (s) TestEDSHandleResponse(t *testing.T) { name string edsResponse *v2xdspb.DiscoveryResponse wantErr bool - wantUpdate map[string]xdsclient.EndpointsUpdateErr + wantUpdate map[string]xdsclient.EndpointsUpdateErrTuple wantUpdateMD xdsclient.UpdateMetadata wantUpdateErr bool }{ @@ -113,7 +113,7 @@ func (s) TestEDSHandleResponse(t *testing.T) { name: "one-uninterestring-assignment", edsResponse: goodEDSResponse2, wantErr: false, - wantUpdate: map[string]xdsclient.EndpointsUpdateErr{ + wantUpdate: map[string]xdsclient.EndpointsUpdateErrTuple{ "not-goodEDSName": {Update: xdsclient.EndpointsUpdate{ Localities: []xdsclient.Locality{ { @@ -136,7 +136,7 @@ func (s) TestEDSHandleResponse(t *testing.T) { name: "one-good-assignment", edsResponse: goodEDSResponse1, wantErr: false, - wantUpdate: map[string]xdsclient.EndpointsUpdateErr{ + wantUpdate: map[string]xdsclient.EndpointsUpdateErrTuple{ goodEDSName: {Update: xdsclient.EndpointsUpdate{ Localities: []xdsclient.Locality{ { diff --git a/xds/internal/xdsclient/v2/lds_test.go b/xds/internal/xdsclient/v2/lds_test.go index 3e9fff0f580a..a0600550095b 100644 --- a/xds/internal/xdsclient/v2/lds_test.go +++ b/xds/internal/xdsclient/v2/lds_test.go @@ -36,7 +36,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name string ldsResponse *v2xdspb.DiscoveryResponse wantErr bool - wantUpdate map[string]xdsclient.ListenerUpdateErr + wantUpdate map[string]xdsclient.ListenerUpdateErrTuple wantUpdateMD xdsclient.UpdateMetadata wantUpdateErr bool }{ @@ -75,7 +75,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name: "no-apiListener-in-response", ldsResponse: noAPIListenerLDSResponse, wantErr: true, - wantUpdate: map[string]xdsclient.ListenerUpdateErr{ + wantUpdate: map[string]xdsclient.ListenerUpdateErrTuple{ goodLDSTarget1: {Err: cmpopts.AnyError}, }, wantUpdateMD: xdsclient.UpdateMetadata{ @@ -91,7 +91,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name: "one-good-listener", ldsResponse: goodLDSResponse1, wantErr: false, - wantUpdate: map[string]xdsclient.ListenerUpdateErr{ + wantUpdate: map[string]xdsclient.ListenerUpdateErrTuple{ goodLDSTarget1: {Update: xdsclient.ListenerUpdate{RouteConfigName: goodRouteName1, Raw: marshaledListener1}}, }, wantUpdateMD: xdsclient.UpdateMetadata{ @@ -105,7 +105,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name: "multiple-good-listener", ldsResponse: ldsResponseWithMultipleResources, wantErr: false, - wantUpdate: map[string]xdsclient.ListenerUpdateErr{ + wantUpdate: map[string]xdsclient.ListenerUpdateErrTuple{ goodLDSTarget1: {Update: xdsclient.ListenerUpdate{RouteConfigName: goodRouteName1, Raw: marshaledListener1}}, goodLDSTarget2: {Update: xdsclient.ListenerUpdate{RouteConfigName: goodRouteName1, Raw: marshaledListener2}}, }, @@ -121,7 +121,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name: "good-bad-ugly-listeners", ldsResponse: goodBadUglyLDSResponse, wantErr: true, - wantUpdate: map[string]xdsclient.ListenerUpdateErr{ + wantUpdate: map[string]xdsclient.ListenerUpdateErrTuple{ goodLDSTarget1: {Update: xdsclient.ListenerUpdate{RouteConfigName: goodRouteName1, Raw: marshaledListener1}}, goodLDSTarget2: {Err: cmpopts.AnyError}, }, @@ -138,7 +138,7 @@ func (s) TestLDSHandleResponse(t *testing.T) { name: "one-uninteresting-listener", ldsResponse: goodLDSResponse2, wantErr: false, - wantUpdate: map[string]xdsclient.ListenerUpdateErr{ + wantUpdate: map[string]xdsclient.ListenerUpdateErrTuple{ goodLDSTarget2: {Update: xdsclient.ListenerUpdate{RouteConfigName: goodRouteName1, Raw: marshaledListener2}}, }, wantUpdateMD: xdsclient.UpdateMetadata{ diff --git a/xds/internal/xdsclient/v2/rds_test.go b/xds/internal/xdsclient/v2/rds_test.go index 32b721387bed..b5e019baa458 100644 --- a/xds/internal/xdsclient/v2/rds_test.go +++ b/xds/internal/xdsclient/v2/rds_test.go @@ -50,7 +50,7 @@ func (s) TestRDSHandleResponseWithRouting(t *testing.T) { name string rdsResponse *xdspb.DiscoveryResponse wantErr bool - wantUpdate map[string]xdsclient.RouteConfigUpdateErr + wantUpdate map[string]xdsclient.RouteConfigUpdateErrTuple wantUpdateMD xdsclient.UpdateMetadata wantUpdateErr bool }{ @@ -89,7 +89,7 @@ func (s) TestRDSHandleResponseWithRouting(t *testing.T) { name: "no-virtual-hosts-in-response", rdsResponse: noVirtualHostsInRDSResponse, wantErr: false, - wantUpdate: map[string]xdsclient.RouteConfigUpdateErr{ + wantUpdate: map[string]xdsclient.RouteConfigUpdateErrTuple{ goodRouteName1: {Update: xdsclient.RouteConfigUpdate{ VirtualHosts: nil, Raw: marshaledNoVirtualHostsRouteConfig, @@ -105,7 +105,7 @@ func (s) TestRDSHandleResponseWithRouting(t *testing.T) { name: "one-uninteresting-route-config", rdsResponse: goodRDSResponse2, wantErr: false, - wantUpdate: map[string]xdsclient.RouteConfigUpdateErr{ + wantUpdate: map[string]xdsclient.RouteConfigUpdateErrTuple{ goodRouteName2: {Update: xdsclient.RouteConfigUpdate{ VirtualHosts: []*xdsclient.VirtualHost{ { @@ -135,7 +135,7 @@ func (s) TestRDSHandleResponseWithRouting(t *testing.T) { name: "one-good-route-config", rdsResponse: goodRDSResponse1, wantErr: false, - wantUpdate: map[string]xdsclient.RouteConfigUpdateErr{ + wantUpdate: map[string]xdsclient.RouteConfigUpdateErrTuple{ goodRouteName1: {Update: xdsclient.RouteConfigUpdate{ VirtualHosts: []*xdsclient.VirtualHost{ { diff --git a/xds/internal/xdsclient/watchers_cluster_test.go b/xds/internal/xdsclient/watchers_cluster_test.go index 0dd1dcec65d0..bbfc1e96dcf7 100644 --- a/xds/internal/xdsclient/watchers_cluster_test.go +++ b/xds/internal/xdsclient/watchers_cluster_test.go @@ -52,20 +52,20 @@ func (s) TestClusterWatch(t *testing.T) { clusterUpdateCh := testutils.NewChannel() cancelWatch := client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := ClusterUpdate{ClusterName: testEDSName} - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } // Another update, with an extra resource for a different resource name. - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName: {Update: wantUpdate}, "randomName": {}, }, UpdateMetadata{}) @@ -75,7 +75,7 @@ func (s) TestClusterWatch(t *testing.T) { // Cancel watch, and send update again. cancelWatch() - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := clusterUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -110,7 +110,7 @@ func (s) TestClusterTwoWatchSameResourceName(t *testing.T) { clusterUpdateCh := testutils.NewChannel() clusterUpdateChs = append(clusterUpdateChs, clusterUpdateCh) cancelLastWatch = client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -123,7 +123,7 @@ func (s) TestClusterTwoWatchSameResourceName(t *testing.T) { } wantUpdate := ClusterUpdate{ClusterName: testEDSName} - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count; i++ { if err := verifyClusterUpdate(ctx, clusterUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -132,7 +132,7 @@ func (s) TestClusterTwoWatchSameResourceName(t *testing.T) { // Cancel the last watch, and send update again. cancelLastWatch() - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count-1; i++ { if err := verifyClusterUpdate(ctx, clusterUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -173,7 +173,7 @@ func (s) TestClusterThreeWatchDifferentResourceName(t *testing.T) { clusterUpdateCh := testutils.NewChannel() clusterUpdateChs = append(clusterUpdateChs, clusterUpdateCh) client.WatchCluster(testCDSName+"1", func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -188,7 +188,7 @@ func (s) TestClusterThreeWatchDifferentResourceName(t *testing.T) { // Third watch for a different name. clusterUpdateCh2 := testutils.NewChannel() client.WatchCluster(testCDSName+"2", func(update ClusterUpdate, err error) { - clusterUpdateCh2.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh2.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -196,7 +196,7 @@ func (s) TestClusterThreeWatchDifferentResourceName(t *testing.T) { wantUpdate1 := ClusterUpdate{ClusterName: testEDSName + "1"} wantUpdate2 := ClusterUpdate{ClusterName: testEDSName + "2"} - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName + "1": {Update: wantUpdate1}, testCDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -233,14 +233,14 @@ func (s) TestClusterWatchAfterCache(t *testing.T) { clusterUpdateCh := testutils.NewChannel() client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := ClusterUpdate{ClusterName: testEDSName} - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName: {Update: wantUpdate}, }, UpdateMetadata{}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate, nil); err != nil { @@ -250,7 +250,7 @@ func (s) TestClusterWatchAfterCache(t *testing.T) { // Another watch for the resource in cache. clusterUpdateCh2 := testutils.NewChannel() client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh2.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh2.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() @@ -294,7 +294,7 @@ func (s) TestClusterWatchExpiryTimer(t *testing.T) { clusterUpdateCh := testutils.NewChannel() client.WatchCluster(testCDSName, func(u ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: u, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: u, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -304,7 +304,7 @@ func (s) TestClusterWatchExpiryTimer(t *testing.T) { if err != nil { t.Fatalf("timeout when waiting for cluster update: %v", err) } - gotUpdate := u.(ClusterUpdateErr) + gotUpdate := u.(ClusterUpdateErrTuple) if gotUpdate.Err == nil || !cmp.Equal(gotUpdate.Update, ClusterUpdate{}) { t.Fatalf("unexpected clusterUpdate: (%v, %v), want: (ClusterUpdate{}, nil)", gotUpdate.Update, gotUpdate.Err) } @@ -333,14 +333,14 @@ func (s) TestClusterWatchExpiryTimerStop(t *testing.T) { clusterUpdateCh := testutils.NewChannel() client.WatchCluster(testCDSName, func(u ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: u, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: u, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := ClusterUpdate{ClusterName: testEDSName} - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName: {Update: wantUpdate}, }, UpdateMetadata{}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, wantUpdate, nil); err != nil { @@ -381,7 +381,7 @@ func (s) TestClusterResourceRemoved(t *testing.T) { clusterUpdateCh1 := testutils.NewChannel() client.WatchCluster(testCDSName+"1", func(update ClusterUpdate, err error) { - clusterUpdateCh1.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh1.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -390,7 +390,7 @@ func (s) TestClusterResourceRemoved(t *testing.T) { // Another watch for a different name. clusterUpdateCh2 := testutils.NewChannel() client.WatchCluster(testCDSName+"2", func(update ClusterUpdate, err error) { - clusterUpdateCh2.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh2.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -398,7 +398,7 @@ func (s) TestClusterResourceRemoved(t *testing.T) { wantUpdate1 := ClusterUpdate{ClusterName: testEDSName + "1"} wantUpdate2 := ClusterUpdate{ClusterName: testEDSName + "2"} - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName + "1": {Update: wantUpdate1}, testCDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -410,10 +410,10 @@ func (s) TestClusterResourceRemoved(t *testing.T) { } // Send another update to remove resource 1. - client.NewClusters(map[string]ClusterUpdateErr{testCDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) // Watcher 1 should get an error. - if u, err := clusterUpdateCh1.Receive(ctx); err != nil || ErrType(u.(ClusterUpdateErr).Err) != ErrorTypeResourceNotFound { + if u, err := clusterUpdateCh1.Receive(ctx); err != nil || ErrType(u.(ClusterUpdateErrTuple).Err) != ErrorTypeResourceNotFound { t.Errorf("unexpected clusterUpdate: %v, error receiving from channel: %v, want update with error resource not found", u, err) } @@ -423,7 +423,7 @@ func (s) TestClusterResourceRemoved(t *testing.T) { } // Send one more update without resource 1. - client.NewClusters(map[string]ClusterUpdateErr{testCDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) // Watcher 1 should not see an update. sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) @@ -460,7 +460,7 @@ func (s) TestClusterWatchNACKError(t *testing.T) { clusterUpdateCh := testutils.NewChannel() cancelWatch := client.WatchCluster(testCDSName, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) defer cancelWatch() if _, err := apiClient.addWatches[ClusterResource].Receive(ctx); err != nil { @@ -468,7 +468,7 @@ func (s) TestClusterWatchNACKError(t *testing.T) { } wantError := fmt.Errorf("testing error") - client.NewClusters(map[string]ClusterUpdateErr{testCDSName: { + client.NewClusters(map[string]ClusterUpdateErrTuple{testCDSName: { Err: wantError, }}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) if err := verifyClusterUpdate(ctx, clusterUpdateCh, ClusterUpdate{}, wantError); err != nil { @@ -504,7 +504,7 @@ func (s) TestClusterWatchPartialValid(t *testing.T) { for _, name := range []string{testCDSName, badResourceName} { clusterUpdateCh := testutils.NewChannel() cancelWatch := client.WatchCluster(name, func(update ClusterUpdate, err error) { - clusterUpdateCh.Send(ClusterUpdateErr{Update: update, Err: err}) + clusterUpdateCh.Send(ClusterUpdateErrTuple{Update: update, Err: err}) }) defer func() { cancelWatch() @@ -520,7 +520,7 @@ func (s) TestClusterWatchPartialValid(t *testing.T) { wantError := fmt.Errorf("testing error") wantError2 := fmt.Errorf("individual error") - client.NewClusters(map[string]ClusterUpdateErr{ + client.NewClusters(map[string]ClusterUpdateErrTuple{ testCDSName: {Update: ClusterUpdate{ClusterName: testEDSName}}, badResourceName: {Err: wantError2}, }, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) diff --git a/xds/internal/xdsclient/watchers_endpoints_test.go b/xds/internal/xdsclient/watchers_endpoints_test.go index f25cff06b69d..e9b726c003e5 100644 --- a/xds/internal/xdsclient/watchers_endpoints_test.go +++ b/xds/internal/xdsclient/watchers_endpoints_test.go @@ -70,20 +70,20 @@ func (s) TestEndpointsWatch(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[EndpointsResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := EndpointsUpdate{Localities: []Locality{testLocalities[0]}} - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyEndpointsUpdate(ctx, endpointsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } // Another update for a different resource name. - client.NewEndpoints(map[string]EndpointsUpdateErr{"randomName": {}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{"randomName": {}}, UpdateMetadata{}) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := endpointsUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -92,7 +92,7 @@ func (s) TestEndpointsWatch(t *testing.T) { // Cancel watch, and send update again. cancelWatch() - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) sCtx, sCancel = context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := endpointsUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -129,7 +129,7 @@ func (s) TestEndpointsTwoWatchSameResourceName(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() endpointsUpdateChs = append(endpointsUpdateChs, endpointsUpdateCh) cancelLastWatch = client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -142,7 +142,7 @@ func (s) TestEndpointsTwoWatchSameResourceName(t *testing.T) { } wantUpdate := EndpointsUpdate{Localities: []Locality{testLocalities[0]}} - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count; i++ { if err := verifyEndpointsUpdate(ctx, endpointsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -151,7 +151,7 @@ func (s) TestEndpointsTwoWatchSameResourceName(t *testing.T) { // Cancel the last watch, and send update again. cancelLastWatch() - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count-1; i++ { if err := verifyEndpointsUpdate(ctx, endpointsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -192,7 +192,7 @@ func (s) TestEndpointsThreeWatchDifferentResourceName(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() endpointsUpdateChs = append(endpointsUpdateChs, endpointsUpdateCh) client.WatchEndpoints(testCDSName+"1", func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -207,7 +207,7 @@ func (s) TestEndpointsThreeWatchDifferentResourceName(t *testing.T) { // Third watch for a different name. endpointsUpdateCh2 := testutils.NewChannel() client.WatchEndpoints(testCDSName+"2", func(update EndpointsUpdate, err error) { - endpointsUpdateCh2.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh2.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[EndpointsResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -215,7 +215,7 @@ func (s) TestEndpointsThreeWatchDifferentResourceName(t *testing.T) { wantUpdate1 := EndpointsUpdate{Localities: []Locality{testLocalities[0]}} wantUpdate2 := EndpointsUpdate{Localities: []Locality{testLocalities[1]}} - client.NewEndpoints(map[string]EndpointsUpdateErr{ + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{ testCDSName + "1": {Update: wantUpdate1}, testCDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -252,14 +252,14 @@ func (s) TestEndpointsWatchAfterCache(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[EndpointsResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := EndpointsUpdate{Localities: []Locality{testLocalities[0]}} - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyEndpointsUpdate(ctx, endpointsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } @@ -267,7 +267,7 @@ func (s) TestEndpointsWatchAfterCache(t *testing.T) { // Another watch for the resource in cache. endpointsUpdateCh2 := testutils.NewChannel() client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh2.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh2.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() @@ -311,7 +311,7 @@ func (s) TestEndpointsWatchExpiryTimer(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[EndpointsResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -321,7 +321,7 @@ func (s) TestEndpointsWatchExpiryTimer(t *testing.T) { if err != nil { t.Fatalf("timeout when waiting for endpoints update: %v", err) } - gotUpdate := u.(EndpointsUpdateErr) + gotUpdate := u.(EndpointsUpdateErrTuple) if gotUpdate.Err == nil || !cmp.Equal(gotUpdate.Update, EndpointsUpdate{}) { t.Fatalf("unexpected endpointsUpdate: (%v, %v), want: (EndpointsUpdate{}, nil)", gotUpdate.Update, gotUpdate.Err) } @@ -349,7 +349,7 @@ func (s) TestEndpointsWatchNACKError(t *testing.T) { endpointsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchEndpoints(testCDSName, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) defer cancelWatch() if _, err := apiClient.addWatches[EndpointsResource].Receive(ctx); err != nil { @@ -357,7 +357,7 @@ func (s) TestEndpointsWatchNACKError(t *testing.T) { } wantError := fmt.Errorf("testing error") - client.NewEndpoints(map[string]EndpointsUpdateErr{testCDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{testCDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) if err := verifyEndpointsUpdate(ctx, endpointsUpdateCh, EndpointsUpdate{}, wantError); err != nil { t.Fatal(err) } @@ -391,7 +391,7 @@ func (s) TestEndpointsWatchPartialValid(t *testing.T) { for _, name := range []string{testCDSName, badResourceName} { endpointsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchEndpoints(name, func(update EndpointsUpdate, err error) { - endpointsUpdateCh.Send(EndpointsUpdateErr{Update: update, Err: err}) + endpointsUpdateCh.Send(EndpointsUpdateErrTuple{Update: update, Err: err}) }) defer func() { cancelWatch() @@ -407,7 +407,7 @@ func (s) TestEndpointsWatchPartialValid(t *testing.T) { wantError := fmt.Errorf("testing error") wantError2 := fmt.Errorf("individual error") - client.NewEndpoints(map[string]EndpointsUpdateErr{ + client.NewEndpoints(map[string]EndpointsUpdateErrTuple{ testCDSName: {Update: EndpointsUpdate{Localities: []Locality{testLocalities[0]}}}, badResourceName: {Err: wantError2}, }, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) diff --git a/xds/internal/xdsclient/watchers_listener_test.go b/xds/internal/xdsclient/watchers_listener_test.go index be7bda4e2b77..62acf24b80d9 100644 --- a/xds/internal/xdsclient/watchers_listener_test.go +++ b/xds/internal/xdsclient/watchers_listener_test.go @@ -50,20 +50,20 @@ func (s) TestLDSWatch(t *testing.T) { ldsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchListener(testLDSName, func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := ListenerUpdate{RouteConfigName: testRDSName} - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyListenerUpdate(ctx, ldsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } // Another update, with an extra resource for a different resource name. - client.NewListeners(map[string]ListenerUpdateErr{ + client.NewListeners(map[string]ListenerUpdateErrTuple{ testLDSName: {Update: wantUpdate}, "randomName": {}, }, UpdateMetadata{}) @@ -73,7 +73,7 @@ func (s) TestLDSWatch(t *testing.T) { // Cancel watch, and send update again. cancelWatch() - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := ldsUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -111,7 +111,7 @@ func (s) TestLDSTwoWatchSameResourceName(t *testing.T) { ldsUpdateCh := testutils.NewChannel() ldsUpdateChs = append(ldsUpdateChs, ldsUpdateCh) cancelLastWatch = client.WatchListener(testLDSName, func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -124,7 +124,7 @@ func (s) TestLDSTwoWatchSameResourceName(t *testing.T) { } wantUpdate := ListenerUpdate{RouteConfigName: testRDSName} - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count; i++ { if err := verifyListenerUpdate(ctx, ldsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -133,7 +133,7 @@ func (s) TestLDSTwoWatchSameResourceName(t *testing.T) { // Cancel the last watch, and send update again. cancelLastWatch() - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count-1; i++ { if err := verifyListenerUpdate(ctx, ldsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -175,7 +175,7 @@ func (s) TestLDSThreeWatchDifferentResourceName(t *testing.T) { ldsUpdateCh := testutils.NewChannel() ldsUpdateChs = append(ldsUpdateChs, ldsUpdateCh) client.WatchListener(testLDSName+"1", func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -190,7 +190,7 @@ func (s) TestLDSThreeWatchDifferentResourceName(t *testing.T) { // Third watch for a different name. ldsUpdateCh2 := testutils.NewChannel() client.WatchListener(testLDSName+"2", func(update ListenerUpdate, err error) { - ldsUpdateCh2.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh2.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -198,7 +198,7 @@ func (s) TestLDSThreeWatchDifferentResourceName(t *testing.T) { wantUpdate1 := ListenerUpdate{RouteConfigName: testRDSName + "1"} wantUpdate2 := ListenerUpdate{RouteConfigName: testRDSName + "2"} - client.NewListeners(map[string]ListenerUpdateErr{ + client.NewListeners(map[string]ListenerUpdateErrTuple{ testLDSName + "1": {Update: wantUpdate1}, testLDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -235,14 +235,14 @@ func (s) TestLDSWatchAfterCache(t *testing.T) { ldsUpdateCh := testutils.NewChannel() client.WatchListener(testLDSName, func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) } wantUpdate := ListenerUpdate{RouteConfigName: testRDSName} - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyListenerUpdate(ctx, ldsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } @@ -250,7 +250,7 @@ func (s) TestLDSWatchAfterCache(t *testing.T) { // Another watch for the resource in cache. ldsUpdateCh2 := testutils.NewChannel() client.WatchListener(testLDSName, func(update ListenerUpdate, err error) { - ldsUpdateCh2.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh2.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() @@ -297,7 +297,7 @@ func (s) TestLDSResourceRemoved(t *testing.T) { ldsUpdateCh1 := testutils.NewChannel() client.WatchListener(testLDSName+"1", func(update ListenerUpdate, err error) { - ldsUpdateCh1.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh1.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -305,7 +305,7 @@ func (s) TestLDSResourceRemoved(t *testing.T) { // Another watch for a different name. ldsUpdateCh2 := testutils.NewChannel() client.WatchListener(testLDSName+"2", func(update ListenerUpdate, err error) { - ldsUpdateCh2.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh2.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -313,7 +313,7 @@ func (s) TestLDSResourceRemoved(t *testing.T) { wantUpdate1 := ListenerUpdate{RouteConfigName: testEDSName + "1"} wantUpdate2 := ListenerUpdate{RouteConfigName: testEDSName + "2"} - client.NewListeners(map[string]ListenerUpdateErr{ + client.NewListeners(map[string]ListenerUpdateErrTuple{ testLDSName + "1": {Update: wantUpdate1}, testLDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -325,10 +325,10 @@ func (s) TestLDSResourceRemoved(t *testing.T) { } // Send another update to remove resource 1. - client.NewListeners(map[string]ListenerUpdateErr{testLDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) // Watcher 1 should get an error. - if u, err := ldsUpdateCh1.Receive(ctx); err != nil || ErrType(u.(ListenerUpdateErr).Err) != ErrorTypeResourceNotFound { + if u, err := ldsUpdateCh1.Receive(ctx); err != nil || ErrType(u.(ListenerUpdateErrTuple).Err) != ErrorTypeResourceNotFound { t.Errorf("unexpected ListenerUpdate: %v, error receiving from channel: %v, want update with error resource not found", u, err) } @@ -338,7 +338,7 @@ func (s) TestLDSResourceRemoved(t *testing.T) { } // Send one more update without resource 1. - client.NewListeners(map[string]ListenerUpdateErr{testLDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName + "2": {Update: wantUpdate2}}, UpdateMetadata{}) // Watcher 1 should not see an update. sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) @@ -375,7 +375,7 @@ func (s) TestListenerWatchNACKError(t *testing.T) { ldsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchListener(testLDSName, func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) defer cancelWatch() if _, err := apiClient.addWatches[ListenerResource].Receive(ctx); err != nil { @@ -383,7 +383,7 @@ func (s) TestListenerWatchNACKError(t *testing.T) { } wantError := fmt.Errorf("testing error") - client.NewListeners(map[string]ListenerUpdateErr{testLDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) + client.NewListeners(map[string]ListenerUpdateErrTuple{testLDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) if err := verifyListenerUpdate(ctx, ldsUpdateCh, ListenerUpdate{}, wantError); err != nil { t.Fatal(err) } @@ -417,7 +417,7 @@ func (s) TestListenerWatchPartialValid(t *testing.T) { for _, name := range []string{testLDSName, badResourceName} { ldsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchListener(name, func(update ListenerUpdate, err error) { - ldsUpdateCh.Send(ListenerUpdateErr{Update: update, Err: err}) + ldsUpdateCh.Send(ListenerUpdateErrTuple{Update: update, Err: err}) }) defer func() { cancelWatch() @@ -433,7 +433,7 @@ func (s) TestListenerWatchPartialValid(t *testing.T) { wantError := fmt.Errorf("testing error") wantError2 := fmt.Errorf("individual error") - client.NewListeners(map[string]ListenerUpdateErr{ + client.NewListeners(map[string]ListenerUpdateErrTuple{ testLDSName: {Update: ListenerUpdate{RouteConfigName: testEDSName}}, badResourceName: {Err: wantError2}, }, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) diff --git a/xds/internal/xdsclient/watchers_route_test.go b/xds/internal/xdsclient/watchers_route_test.go index 63f10ab13196..cfb5449befd8 100644 --- a/xds/internal/xdsclient/watchers_route_test.go +++ b/xds/internal/xdsclient/watchers_route_test.go @@ -52,7 +52,7 @@ func (s) TestRDSWatch(t *testing.T) { rdsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchRouteConfig(testRDSName, func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[RouteConfigResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -66,13 +66,13 @@ func (s) TestRDSWatch(t *testing.T) { }, }, } - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyRouteConfigUpdate(ctx, rdsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } // Another update for a different resource name. - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{"randomName": {}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{"randomName": {}}, UpdateMetadata{}) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := rdsUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -81,7 +81,7 @@ func (s) TestRDSWatch(t *testing.T) { // Cancel watch, and send update again. cancelWatch() - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) sCtx, sCancel = context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() if u, err := rdsUpdateCh.Receive(sCtx); err != context.DeadlineExceeded { @@ -118,7 +118,7 @@ func (s) TestRDSTwoWatchSameResourceName(t *testing.T) { rdsUpdateCh := testutils.NewChannel() rdsUpdateChs = append(rdsUpdateChs, rdsUpdateCh) cancelLastWatch = client.WatchRouteConfig(testRDSName, func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -138,7 +138,7 @@ func (s) TestRDSTwoWatchSameResourceName(t *testing.T) { }, }, } - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count; i++ { if err := verifyRouteConfigUpdate(ctx, rdsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -147,7 +147,7 @@ func (s) TestRDSTwoWatchSameResourceName(t *testing.T) { // Cancel the last watch, and send update again. cancelLastWatch() - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) for i := 0; i < count-1; i++ { if err := verifyRouteConfigUpdate(ctx, rdsUpdateChs[i], wantUpdate, nil); err != nil { t.Fatal(err) @@ -188,7 +188,7 @@ func (s) TestRDSThreeWatchDifferentResourceName(t *testing.T) { rdsUpdateCh := testutils.NewChannel() rdsUpdateChs = append(rdsUpdateChs, rdsUpdateCh) client.WatchRouteConfig(testRDSName+"1", func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) if i == 0 { @@ -203,7 +203,7 @@ func (s) TestRDSThreeWatchDifferentResourceName(t *testing.T) { // Third watch for a different name. rdsUpdateCh2 := testutils.NewChannel() client.WatchRouteConfig(testRDSName+"2", func(update RouteConfigUpdate, err error) { - rdsUpdateCh2.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh2.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[RouteConfigResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -225,7 +225,7 @@ func (s) TestRDSThreeWatchDifferentResourceName(t *testing.T) { }, }, } - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{ + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{ testRDSName + "1": {Update: wantUpdate1}, testRDSName + "2": {Update: wantUpdate2}, }, UpdateMetadata{}) @@ -262,7 +262,7 @@ func (s) TestRDSWatchAfterCache(t *testing.T) { rdsUpdateCh := testutils.NewChannel() client.WatchRouteConfig(testRDSName, func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) if _, err := apiClient.addWatches[RouteConfigResource].Receive(ctx); err != nil { t.Fatalf("want new watch to start, got error %v", err) @@ -276,7 +276,7 @@ func (s) TestRDSWatchAfterCache(t *testing.T) { }, }, } - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testRDSName: {Update: wantUpdate}}, UpdateMetadata{}) if err := verifyRouteConfigUpdate(ctx, rdsUpdateCh, wantUpdate, nil); err != nil { t.Fatal(err) } @@ -284,7 +284,7 @@ func (s) TestRDSWatchAfterCache(t *testing.T) { // Another watch for the resource in cache. rdsUpdateCh2 := testutils.NewChannel() client.WatchRouteConfig(testRDSName, func(update RouteConfigUpdate, err error) { - rdsUpdateCh2.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh2.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) sCtx, sCancel := context.WithTimeout(ctx, defaultTestShortTimeout) defer sCancel() @@ -293,7 +293,7 @@ func (s) TestRDSWatchAfterCache(t *testing.T) { } // New watch should receives the update. - if u, err := rdsUpdateCh2.Receive(ctx); err != nil || !cmp.Equal(u, RouteConfigUpdateErr{wantUpdate, nil}, cmp.AllowUnexported(RouteConfigUpdateErr{})) { + if u, err := rdsUpdateCh2.Receive(ctx); err != nil || !cmp.Equal(u, RouteConfigUpdateErrTuple{wantUpdate, nil}, cmp.AllowUnexported(RouteConfigUpdateErrTuple{})) { t.Errorf("unexpected RouteConfigUpdate: %v, error receiving from channel: %v", u, err) } @@ -327,7 +327,7 @@ func (s) TestRouteWatchNACKError(t *testing.T) { rdsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchRouteConfig(testCDSName, func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) defer cancelWatch() if _, err := apiClient.addWatches[RouteConfigResource].Receive(ctx); err != nil { @@ -335,7 +335,7 @@ func (s) TestRouteWatchNACKError(t *testing.T) { } wantError := fmt.Errorf("testing error") - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{testCDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{testCDSName: {Err: wantError}}, UpdateMetadata{ErrState: &UpdateErrorMetadata{Err: wantError}}) if err := verifyRouteConfigUpdate(ctx, rdsUpdateCh, RouteConfigUpdate{}, wantError); err != nil { t.Fatal(err) } @@ -369,7 +369,7 @@ func (s) TestRouteWatchPartialValid(t *testing.T) { for _, name := range []string{testRDSName, badResourceName} { rdsUpdateCh := testutils.NewChannel() cancelWatch := client.WatchRouteConfig(name, func(update RouteConfigUpdate, err error) { - rdsUpdateCh.Send(RouteConfigUpdateErr{Update: update, Err: err}) + rdsUpdateCh.Send(RouteConfigUpdateErrTuple{Update: update, Err: err}) }) defer func() { cancelWatch() @@ -385,7 +385,7 @@ func (s) TestRouteWatchPartialValid(t *testing.T) { wantError := fmt.Errorf("testing error") wantError2 := fmt.Errorf("individual error") - client.NewRouteConfigs(map[string]RouteConfigUpdateErr{ + client.NewRouteConfigs(map[string]RouteConfigUpdateErrTuple{ testRDSName: {Update: RouteConfigUpdate{VirtualHosts: []*VirtualHost{{ Domains: []string{testLDSName}, Routes: []*Route{{Prefix: newStringP(""), WeightedClusters: map[string]WeightedCluster{testCDSName: {Weight: 1}}}}, diff --git a/xds/internal/xdsclient/xds.go b/xds/internal/xdsclient/xds.go index 53677d431e9c..ee4b69752f98 100644 --- a/xds/internal/xdsclient/xds.go +++ b/xds/internal/xdsclient/xds.go @@ -58,8 +58,8 @@ const transportSocketName = "envoy.transport_sockets.tls" // UnmarshalListener processes resources received in an LDS response, validates // them, and transforms them into a native struct which contains only fields we // are interested in. -func UnmarshalListener(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]ListenerUpdateErr, UpdateMetadata, error) { - update := make(map[string]ListenerUpdateErr) +func UnmarshalListener(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]ListenerUpdateErrTuple, UpdateMetadata, error) { + update := make(map[string]ListenerUpdateErrTuple) md, err := processAllResources(version, resources, logger, update) return update, md, err } @@ -296,8 +296,8 @@ func processServerSideListener(lis *v3listenerpb.Listener) (*ListenerUpdate, err // validates them, and transforms them into a native struct which contains only // fields we are interested in. The provided hostname determines the route // configuration resources of interest. -func UnmarshalRouteConfig(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]RouteConfigUpdateErr, UpdateMetadata, error) { - update := make(map[string]RouteConfigUpdateErr) +func UnmarshalRouteConfig(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]RouteConfigUpdateErrTuple, UpdateMetadata, error) { + update := make(map[string]RouteConfigUpdateErrTuple) md, err := processAllResources(version, resources, logger, update) return update, md, err } @@ -631,8 +631,8 @@ func hashPoliciesProtoToSlice(policies []*v3routepb.RouteAction_HashPolicy, logg // UnmarshalCluster processes resources received in an CDS response, validates // them, and transforms them into a native struct which contains only fields we // are interested in. -func UnmarshalCluster(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]ClusterUpdateErr, UpdateMetadata, error) { - update := make(map[string]ClusterUpdateErr) +func UnmarshalCluster(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]ClusterUpdateErrTuple, UpdateMetadata, error) { + update := make(map[string]ClusterUpdateErrTuple) md, err := processAllResources(version, resources, logger, update) return update, md, err } @@ -894,8 +894,8 @@ func circuitBreakersFromCluster(cluster *v3clusterpb.Cluster) *uint32 { // UnmarshalEndpoints processes resources received in an EDS response, // validates them, and transforms them into a native struct which contains only // fields we are interested in. -func UnmarshalEndpoints(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]EndpointsUpdateErr, UpdateMetadata, error) { - update := make(map[string]EndpointsUpdateErr) +func UnmarshalEndpoints(version string, resources []*anypb.Any, logger *grpclog.PrefixLogger) (map[string]EndpointsUpdateErrTuple, UpdateMetadata, error) { + update := make(map[string]EndpointsUpdateErrTuple) md, err := processAllResources(version, resources, logger, update) return update, md, err } @@ -989,26 +989,34 @@ func parseEDSRespProto(m *v3endpointpb.ClusterLoadAssignment) (EndpointsUpdate, return ret, nil } -// ListenerUpdateErr is a tuple with the update and error. -type ListenerUpdateErr struct { +// ListenerUpdateErrTuple is a tuple with the update and error. It contains the +// results from unmarshal functions. It's used to pass unmarshal results of +// multiple resources together, e.g. in maps like `map[string]{Update,error}`. +type ListenerUpdateErrTuple struct { Update ListenerUpdate Err error } -// RouteConfigUpdateErr is a tuple with the update and error. -type RouteConfigUpdateErr struct { +// RouteConfigUpdateErrTuple is a tuple with the update and error. It contains +// the results from unmarshal functions. It's used to pass unmarshal results of +// multiple resources together, e.g. in maps like `map[string]{Update,error}`. +type RouteConfigUpdateErrTuple struct { Update RouteConfigUpdate Err error } -// ClusterUpdateErr is a tuple with the update and error. -type ClusterUpdateErr struct { +// ClusterUpdateErrTuple is a tuple with the update and error. It contains the +// results from unmarshal functions. It's used to pass unmarshal results of +// multiple resources together, e.g. in maps like `map[string]{Update,error}`. +type ClusterUpdateErrTuple struct { Update ClusterUpdate Err error } -// EndpointsUpdateErr is a tuple with the update and error. -type EndpointsUpdateErr struct { +// EndpointsUpdateErrTuple is a tuple with the update and error. It contains the +// results from unmarshal functions. It's used to pass unmarshal results of +// multiple resources together, e.g. in maps like `map[string]{Update,error}`. +type EndpointsUpdateErrTuple struct { Update EndpointsUpdate Err error } @@ -1033,10 +1041,10 @@ func processAllResources(version string, resources []*anypb.Any, logger *grpclog for _, r := range resources { switch ret2 := ret.(type) { - case map[string]ListenerUpdateErr: + case map[string]ListenerUpdateErrTuple: name, update, err := unmarshalListenerResource(r, logger) if err == nil { - ret2[name] = ListenerUpdateErr{Update: update} + ret2[name] = ListenerUpdateErrTuple{Update: update} continue } if name == "" { @@ -1046,11 +1054,11 @@ func processAllResources(version string, resources []*anypb.Any, logger *grpclog perResourceErrors[name] = err // Add place holder in the map so we know this resource name was in // the response. - ret2[name] = ListenerUpdateErr{Err: err} - case map[string]RouteConfigUpdateErr: + ret2[name] = ListenerUpdateErrTuple{Err: err} + case map[string]RouteConfigUpdateErrTuple: name, update, err := unmarshalRouteConfigResource(r, logger) if err == nil { - ret2[name] = RouteConfigUpdateErr{Update: update} + ret2[name] = RouteConfigUpdateErrTuple{Update: update} continue } if name == "" { @@ -1060,11 +1068,11 @@ func processAllResources(version string, resources []*anypb.Any, logger *grpclog perResourceErrors[name] = err // Add place holder in the map so we know this resource name was in // the response. - ret2[name] = RouteConfigUpdateErr{Err: err} - case map[string]ClusterUpdateErr: + ret2[name] = RouteConfigUpdateErrTuple{Err: err} + case map[string]ClusterUpdateErrTuple: name, update, err := unmarshalClusterResource(r, logger) if err == nil { - ret2[name] = ClusterUpdateErr{Update: update} + ret2[name] = ClusterUpdateErrTuple{Update: update} continue } if name == "" { @@ -1074,11 +1082,11 @@ func processAllResources(version string, resources []*anypb.Any, logger *grpclog perResourceErrors[name] = err // Add place holder in the map so we know this resource name was in // the response. - ret2[name] = ClusterUpdateErr{Err: err} - case map[string]EndpointsUpdateErr: + ret2[name] = ClusterUpdateErrTuple{Err: err} + case map[string]EndpointsUpdateErrTuple: name, update, err := unmarshalEndpointsResource(r, logger) if err == nil { - ret2[name] = EndpointsUpdateErr{Update: update} + ret2[name] = EndpointsUpdateErrTuple{Update: update} continue } if name == "" { @@ -1088,7 +1096,7 @@ func processAllResources(version string, resources []*anypb.Any, logger *grpclog perResourceErrors[name] = err // Add place holder in the map so we know this resource name was in // the response. - ret2[name] = EndpointsUpdateErr{Err: err} + ret2[name] = EndpointsUpdateErrTuple{Err: err} } }