...
1
18
19 package google
20
21 import (
22 "context"
23 "testing"
24
25 "google.golang.org/grpc/credentials"
26 icredentials "google.golang.org/grpc/internal/credentials"
27 "google.golang.org/grpc/internal/xds"
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: xds.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 }
59
View as plain text