google.golang.org/grpc@v1.62.1/credentials/google/xds_test.go (about) 1 /* 2 * 3 * Copyright 2021 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package google 20 21 import ( 22 "context" 23 "testing" 24 25 "google.golang.org/grpc/credentials" 26 "google.golang.org/grpc/internal" 27 icredentials "google.golang.org/grpc/internal/credentials" 28 "google.golang.org/grpc/resolver" 29 ) 30 31 func (s) TestIsDirectPathCluster(t *testing.T) { 32 c := func(cluster string) context.Context { 33 return icredentials.NewClientHandshakeInfoContext(context.Background(), credentials.ClientHandshakeInfo{ 34 Attributes: internal.SetXDSHandshakeClusterName(resolver.Address{}, cluster).Attributes, 35 }) 36 } 37 38 testCases := []struct { 39 name string 40 ctx context.Context 41 want bool 42 }{ 43 {"not an xDS cluster", context.Background(), false}, 44 {"cfe", c("google_cfe_bigtable.googleapis.com"), false}, 45 {"non-cfe", c("google_bigtable.googleapis.com"), true}, 46 {"starts with xdstp but not cfe format", c("xdstp:google_cfe_bigtable.googleapis.com"), true}, 47 {"no authority", c("xdstp:///envoy.config.cluster.v3.Cluster/google_cfe_"), true}, 48 {"wrong authority", c("xdstp://foo.bar/envoy.config.cluster.v3.Cluster/google_cfe_"), true}, 49 {"xdstp CFE", c("xdstp://traffic-director-c2p.xds.googleapis.com/envoy.config.cluster.v3.Cluster/google_cfe_"), false}, 50 } 51 for _, tc := range testCases { 52 t.Run(tc.name, func(t *testing.T) { 53 if got := isDirectPathCluster(tc.ctx); got != tc.want { 54 t.Errorf("isDirectPathCluster(_) = %v; want %v", got, tc.want) 55 } 56 }) 57 } 58 }