...
1
17
18
19 package testutils
20
21 import (
22 "fmt"
23 "testing"
24
25 "google.golang.org/grpc/internal/xds/bootstrap"
26 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
27 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource/version"
28 )
29
30
31
32 func BuildResourceName(typeName, auth, id string, ctxParams map[string]string) string {
33 var typS string
34 switch typeName {
35 case xdsresource.ListenerResourceTypeName:
36 typS = version.V3ListenerType
37 case xdsresource.RouteConfigTypeName:
38 typS = version.V3RouteConfigType
39 case xdsresource.ClusterResourceTypeName:
40 typS = version.V3ClusterType
41 case xdsresource.EndpointsResourceTypeName:
42 typS = version.V3EndpointsType
43 default:
44
45
46 typS = typeName
47 }
48 return (&xdsresource.Name{
49 Scheme: "xdstp",
50 Authority: auth,
51 Type: typS,
52 ID: id,
53 ContextParams: ctxParams,
54 }).String()
55 }
56
57
58
59 func ServerConfigForAddress(t *testing.T, addr string) *bootstrap.ServerConfig {
60 t.Helper()
61
62 jsonCfg := fmt.Sprintf(`{
63 "server_uri": "%s",
64 "channel_creds": [{"type": "insecure"}],
65 "server_features": ["xds_v3"]
66 }`, addr)
67 sc, err := bootstrap.ServerConfigFromJSON([]byte(jsonCfg))
68 if err != nil {
69 t.Fatalf("Failed to create server config from JSON %s: %v", jsonCfg, err)
70 }
71 return sc
72 }
73
View as plain text