github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/grpc/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  	"github.com/hxx258456/ccgo/grpc/xds/internal/xdsclient/xdsresource"
    23  	"github.com/hxx258456/ccgo/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(typ xdsresource.ResourceType, auth, id string, ctxParams map[string]string) string {
    29  	var typS string
    30  	switch typ {
    31  	case xdsresource.ListenerResource:
    32  		typS = version.V3ListenerType
    33  	case xdsresource.RouteConfigResource:
    34  		typS = version.V3RouteConfigType
    35  	case xdsresource.ClusterResource:
    36  		typS = version.V3ClusterType
    37  	case xdsresource.EndpointsResource:
    38  		typS = version.V3EndpointsType
    39  	}
    40  	return (&xdsresource.Name{
    41  		Scheme:        "xdstp",
    42  		Authority:     auth,
    43  		Type:          typS,
    44  		ID:            id,
    45  		ContextParams: ctxParams,
    46  	}).String()
    47  }