Skip to content

Commit 0ae33e6

Browse files
authored
xdsclient: remove unused test code (#5772)
1 parent 824f449 commit 0ae33e6

File tree

2 files changed

+0
-731
lines changed

2 files changed

+0
-731
lines changed

xds/internal/xdsclient/client_test.go

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,10 @@
1919
package xdsclient
2020

2121
import (
22-
"context"
23-
"fmt"
24-
"strings"
2522
"testing"
2623
"time"
2724

28-
"github.com/google/go-cmp/cmp"
29-
"github.com/google/go-cmp/cmp/cmpopts"
30-
"google.golang.org/grpc/internal/grpclog"
31-
"google.golang.org/grpc/xds/internal/xdsclient/load"
32-
"google.golang.org/grpc/xds/internal/xdsclient/pubsub"
33-
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
34-
35-
"google.golang.org/grpc"
36-
"google.golang.org/grpc/credentials/insecure"
37-
"google.golang.org/grpc/internal/grpcsync"
3825
"google.golang.org/grpc/internal/grpctest"
39-
"google.golang.org/grpc/internal/testutils"
40-
xdstestutils "google.golang.org/grpc/xds/internal/testutils"
41-
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
42-
"google.golang.org/protobuf/testing/protocmp"
4326
)
4427

4528
type s struct {
@@ -54,167 +37,7 @@ const (
5437
testXDSServer = "xds-server"
5538
testXDSServerAuthority = "xds-server-authority"
5639

57-
testAuthority = "test-authority"
58-
testAuthority2 = "test-authority-2"
59-
testLDSName = "test-lds"
60-
testRDSName = "test-rds"
61-
testCDSName = "test-cds"
62-
testEDSName = "test-eds"
63-
6440
defaultTestWatchExpiryTimeout = 500 * time.Millisecond
6541
defaultTestTimeout = 5 * time.Second
6642
defaultTestShortTimeout = 10 * time.Millisecond // For events expected to *not* happen.
6743
)
68-
69-
func newStringP(s string) *string {
70-
return &s
71-
}
72-
73-
func clientOpts() *bootstrap.Config {
74-
return &bootstrap.Config{
75-
XDSServer: &bootstrap.ServerConfig{
76-
ServerURI: testXDSServer,
77-
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
78-
NodeProto: xdstestutils.EmptyNodeProtoV2,
79-
},
80-
Authorities: map[string]*bootstrap.Authority{
81-
testAuthority: {
82-
XDSServer: &bootstrap.ServerConfig{
83-
ServerURI: testXDSServerAuthority,
84-
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
85-
NodeProto: xdstestutils.EmptyNodeProtoV2,
86-
},
87-
},
88-
},
89-
}
90-
}
91-
92-
type testController struct {
93-
// config is the config this controller is created with.
94-
config *bootstrap.ServerConfig
95-
96-
done *grpcsync.Event
97-
addWatches map[xdsresource.ResourceType]*testutils.Channel
98-
removeWatches map[xdsresource.ResourceType]*testutils.Channel
99-
}
100-
101-
func overrideNewController(t *testing.T) *testutils.Channel {
102-
origNewController := newController
103-
ch := testutils.NewChannel()
104-
newController = func(config *bootstrap.ServerConfig, pubsub *pubsub.Pubsub, validator xdsresource.UpdateValidatorFunc, logger *grpclog.PrefixLogger, _ func(int) time.Duration) (controllerInterface, error) {
105-
ret := newTestController(config)
106-
ch.Send(ret)
107-
return ret, nil
108-
}
109-
t.Cleanup(func() { newController = origNewController })
110-
return ch
111-
}
112-
113-
func newTestController(config *bootstrap.ServerConfig) *testController {
114-
addWatches := map[xdsresource.ResourceType]*testutils.Channel{
115-
xdsresource.ListenerResource: testutils.NewChannel(),
116-
xdsresource.RouteConfigResource: testutils.NewChannel(),
117-
xdsresource.ClusterResource: testutils.NewChannel(),
118-
xdsresource.EndpointsResource: testutils.NewChannel(),
119-
}
120-
removeWatches := map[xdsresource.ResourceType]*testutils.Channel{
121-
xdsresource.ListenerResource: testutils.NewChannel(),
122-
xdsresource.RouteConfigResource: testutils.NewChannel(),
123-
xdsresource.ClusterResource: testutils.NewChannel(),
124-
xdsresource.EndpointsResource: testutils.NewChannel(),
125-
}
126-
return &testController{
127-
config: config,
128-
done: grpcsync.NewEvent(),
129-
addWatches: addWatches,
130-
removeWatches: removeWatches,
131-
}
132-
}
133-
134-
func (c *testController) AddWatch(resourceType xdsresource.ResourceType, resourceName string) {
135-
c.addWatches[resourceType].Send(resourceName)
136-
}
137-
138-
func (c *testController) RemoveWatch(resourceType xdsresource.ResourceType, resourceName string) {
139-
c.removeWatches[resourceType].Send(resourceName)
140-
}
141-
142-
func (c *testController) ReportLoad(server string) (*load.Store, func()) {
143-
panic("ReportLoad is not implemented")
144-
}
145-
146-
func (c *testController) Close() {
147-
c.done.Fire()
148-
}
149-
150-
func verifyListenerUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.ListenerUpdate, wantErr error) error {
151-
u, err := updateCh.Receive(ctx)
152-
if err != nil {
153-
return fmt.Errorf("timeout when waiting for listener update: %v", err)
154-
}
155-
gotUpdate := u.(xdsresource.ListenerUpdateErrTuple)
156-
if wantErr != nil {
157-
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
158-
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
159-
}
160-
return nil
161-
}
162-
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
163-
return fmt.Errorf("unexpected endpointsUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
164-
}
165-
return nil
166-
}
167-
168-
func verifyRouteConfigUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.RouteConfigUpdate, wantErr error) error {
169-
u, err := updateCh.Receive(ctx)
170-
if err != nil {
171-
return fmt.Errorf("timeout when waiting for route configuration update: %v", err)
172-
}
173-
gotUpdate := u.(xdsresource.RouteConfigUpdateErrTuple)
174-
if wantErr != nil {
175-
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
176-
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
177-
}
178-
return nil
179-
}
180-
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
181-
return fmt.Errorf("unexpected route config update: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
182-
}
183-
return nil
184-
}
185-
186-
func verifyClusterUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.ClusterUpdate, wantErr error) error {
187-
u, err := updateCh.Receive(ctx)
188-
if err != nil {
189-
return fmt.Errorf("timeout when waiting for cluster update: %v", err)
190-
}
191-
gotUpdate := u.(xdsresource.ClusterUpdateErrTuple)
192-
if wantErr != nil {
193-
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
194-
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
195-
}
196-
return nil
197-
}
198-
if !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
199-
return fmt.Errorf("unexpected clusterUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
200-
}
201-
return nil
202-
}
203-
204-
func verifyEndpointsUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.EndpointsUpdate, wantErr error) error {
205-
u, err := updateCh.Receive(ctx)
206-
if err != nil {
207-
return fmt.Errorf("timeout when waiting for endpoints update: %v", err)
208-
}
209-
gotUpdate := u.(xdsresource.EndpointsUpdateErrTuple)
210-
if wantErr != nil {
211-
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
212-
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
213-
}
214-
return nil
215-
}
216-
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, cmpopts.EquateEmpty(), protocmp.Transform()) {
217-
return fmt.Errorf("unexpected endpointsUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
218-
}
219-
return nil
220-
}

0 commit comments

Comments
 (0)