xds: Move test only utility method to testutils. (#3715)
This commit is contained in:

committed by
GitHub

parent
31d22c78fb
commit
4241954407
@ -39,6 +39,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/grpc/xds/internal"
|
||||
"google.golang.org/grpc/xds/internal/testutils"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -286,7 +287,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) {
|
||||
)
|
||||
}
|
||||
upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{
|
||||
Locality: l.ToProto(),
|
||||
Locality: testutils.LocalityIDToProto(l),
|
||||
TotalSuccessfulRequests: count.success,
|
||||
TotalRequestsInProgress: tempInProgress,
|
||||
TotalErrorRequests: count.failure,
|
||||
@ -298,7 +299,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) {
|
||||
for l, c := range inProgressCounts {
|
||||
if _, ok := counts[l]; !ok {
|
||||
upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{
|
||||
Locality: l.ToProto(),
|
||||
Locality: testutils.LocalityIDToProto(l),
|
||||
TotalRequestsInProgress: c,
|
||||
})
|
||||
}
|
||||
|
@ -21,8 +21,6 @@ package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
|
||||
)
|
||||
|
||||
type clientID string
|
||||
@ -49,12 +47,3 @@ type LocalityID struct {
|
||||
func (l LocalityID) String() string {
|
||||
return fmt.Sprintf("%s-%s-%s", l.Region, l.Zone, l.SubZone)
|
||||
}
|
||||
|
||||
// ToProto convert Locality to the proto representation.
|
||||
func (l LocalityID) ToProto() *corepb.Locality {
|
||||
return &corepb.Locality{
|
||||
Region: l.Region,
|
||||
Zone: l.Zone,
|
||||
SubZone: l.SubZone,
|
||||
}
|
||||
}
|
||||
|
32
xds/internal/testutils/locality.go
Normal file
32
xds/internal/testutils/locality.go
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2020 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package testutils
|
||||
|
||||
import (
|
||||
corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
|
||||
"google.golang.org/grpc/xds/internal"
|
||||
)
|
||||
|
||||
// LocalityIDToProto converts a LocalityID to its proto representation.
|
||||
func LocalityIDToProto(l internal.LocalityID) *corepb.Locality {
|
||||
return &corepb.Locality{
|
||||
Region: l.Region,
|
||||
Zone: l.Zone,
|
||||
SubZone: l.SubZone,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user