Skip to content

Commit

Permalink
xdsclient: remove unused test code (#5772)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars authored Nov 7, 2022
1 parent 824f449 commit 0ae33e6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 731 deletions.
177 changes: 0 additions & 177 deletions xds/internal/xdsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,10 @@
package xdsclient

import (
"context"
"fmt"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"google.golang.org/grpc/internal/grpclog"
"google.golang.org/grpc/xds/internal/xdsclient/load"
"google.golang.org/grpc/xds/internal/xdsclient/pubsub"
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpcsync"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/testutils"
xdstestutils "google.golang.org/grpc/xds/internal/testutils"
"google.golang.org/grpc/xds/internal/xdsclient/bootstrap"
"google.golang.org/protobuf/testing/protocmp"
)

type s struct {
Expand All @@ -54,167 +37,7 @@ const (
testXDSServer = "xds-server"
testXDSServerAuthority = "xds-server-authority"

testAuthority = "test-authority"
testAuthority2 = "test-authority-2"
testLDSName = "test-lds"
testRDSName = "test-rds"
testCDSName = "test-cds"
testEDSName = "test-eds"

defaultTestWatchExpiryTimeout = 500 * time.Millisecond
defaultTestTimeout = 5 * time.Second
defaultTestShortTimeout = 10 * time.Millisecond // For events expected to *not* happen.
)

func newStringP(s string) *string {
return &s
}

func clientOpts() *bootstrap.Config {
return &bootstrap.Config{
XDSServer: &bootstrap.ServerConfig{
ServerURI: testXDSServer,
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: xdstestutils.EmptyNodeProtoV2,
},
Authorities: map[string]*bootstrap.Authority{
testAuthority: {
XDSServer: &bootstrap.ServerConfig{
ServerURI: testXDSServerAuthority,
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: xdstestutils.EmptyNodeProtoV2,
},
},
},
}
}

type testController struct {
// config is the config this controller is created with.
config *bootstrap.ServerConfig

done *grpcsync.Event
addWatches map[xdsresource.ResourceType]*testutils.Channel
removeWatches map[xdsresource.ResourceType]*testutils.Channel
}

func overrideNewController(t *testing.T) *testutils.Channel {
origNewController := newController
ch := testutils.NewChannel()
newController = func(config *bootstrap.ServerConfig, pubsub *pubsub.Pubsub, validator xdsresource.UpdateValidatorFunc, logger *grpclog.PrefixLogger, _ func(int) time.Duration) (controllerInterface, error) {
ret := newTestController(config)
ch.Send(ret)
return ret, nil
}
t.Cleanup(func() { newController = origNewController })
return ch
}

func newTestController(config *bootstrap.ServerConfig) *testController {
addWatches := map[xdsresource.ResourceType]*testutils.Channel{
xdsresource.ListenerResource: testutils.NewChannel(),
xdsresource.RouteConfigResource: testutils.NewChannel(),
xdsresource.ClusterResource: testutils.NewChannel(),
xdsresource.EndpointsResource: testutils.NewChannel(),
}
removeWatches := map[xdsresource.ResourceType]*testutils.Channel{
xdsresource.ListenerResource: testutils.NewChannel(),
xdsresource.RouteConfigResource: testutils.NewChannel(),
xdsresource.ClusterResource: testutils.NewChannel(),
xdsresource.EndpointsResource: testutils.NewChannel(),
}
return &testController{
config: config,
done: grpcsync.NewEvent(),
addWatches: addWatches,
removeWatches: removeWatches,
}
}

func (c *testController) AddWatch(resourceType xdsresource.ResourceType, resourceName string) {
c.addWatches[resourceType].Send(resourceName)
}

func (c *testController) RemoveWatch(resourceType xdsresource.ResourceType, resourceName string) {
c.removeWatches[resourceType].Send(resourceName)
}

func (c *testController) ReportLoad(server string) (*load.Store, func()) {
panic("ReportLoad is not implemented")
}

func (c *testController) Close() {
c.done.Fire()
}

func verifyListenerUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.ListenerUpdate, wantErr error) error {
u, err := updateCh.Receive(ctx)
if err != nil {
return fmt.Errorf("timeout when waiting for listener update: %v", err)
}
gotUpdate := u.(xdsresource.ListenerUpdateErrTuple)
if wantErr != nil {
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
}
return nil
}
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
return fmt.Errorf("unexpected endpointsUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
}
return nil
}

func verifyRouteConfigUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.RouteConfigUpdate, wantErr error) error {
u, err := updateCh.Receive(ctx)
if err != nil {
return fmt.Errorf("timeout when waiting for route configuration update: %v", err)
}
gotUpdate := u.(xdsresource.RouteConfigUpdateErrTuple)
if wantErr != nil {
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
}
return nil
}
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
return fmt.Errorf("unexpected route config update: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
}
return nil
}

func verifyClusterUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.ClusterUpdate, wantErr error) error {
u, err := updateCh.Receive(ctx)
if err != nil {
return fmt.Errorf("timeout when waiting for cluster update: %v", err)
}
gotUpdate := u.(xdsresource.ClusterUpdateErrTuple)
if wantErr != nil {
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
}
return nil
}
if !cmp.Equal(gotUpdate.Update, wantUpdate, protocmp.Transform()) {
return fmt.Errorf("unexpected clusterUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
}
return nil
}

func verifyEndpointsUpdate(ctx context.Context, updateCh *testutils.Channel, wantUpdate xdsresource.EndpointsUpdate, wantErr error) error {
u, err := updateCh.Receive(ctx)
if err != nil {
return fmt.Errorf("timeout when waiting for endpoints update: %v", err)
}
gotUpdate := u.(xdsresource.EndpointsUpdateErrTuple)
if wantErr != nil {
if !strings.Contains(gotUpdate.Err.Error(), wantErr.Error()) {
return fmt.Errorf("unexpected error: %v, want %v", gotUpdate.Err, wantErr)
}
return nil
}
if gotUpdate.Err != nil || !cmp.Equal(gotUpdate.Update, wantUpdate, cmpopts.EquateEmpty(), protocmp.Transform()) {
return fmt.Errorf("unexpected endpointsUpdate: (%v, %v), want: (%v, nil)", gotUpdate.Update, gotUpdate.Err, wantUpdate)
}
return nil
}
Loading

0 comments on commit 0ae33e6

Please sign in to comment.