google.golang.org/grpc@v1.74.2/xds/internal/testutils/testutils.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 // Package testutils provides utility types, for use in xds tests. 19 package testutils 20 21 import ( 22 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource" 23 "google.golang.org/grpc/xds/internal/xdsclient/xdsresource/version" 24 ) 25 26 // BuildResourceName returns the resource name in the format of an xdstp:// 27 // resource. 28 func BuildResourceName(typeName, auth, id string, ctxParams map[string]string) string { 29 var typS string 30 switch typeName { 31 case xdsresource.ListenerResourceTypeName: 32 typS = version.V3ListenerType 33 case xdsresource.RouteConfigTypeName: 34 typS = version.V3RouteConfigType 35 case xdsresource.ClusterResourceTypeName: 36 typS = version.V3ClusterType 37 case xdsresource.EndpointsResourceTypeName: 38 typS = version.V3EndpointsType 39 default: 40 // If the name doesn't match any of the standard resources fallback 41 // to the type name. 42 typS = typeName 43 } 44 return (&xdsresource.Name{ 45 Scheme: "xdstp", 46 Authority: auth, 47 Type: typS, 48 ID: id, 49 ContextParams: ctxParams, 50 }).String() 51 }