Skip to content

Commit 4241954

Browse files
authored
xds: Move test only utility method to testutils. (#3715)
1 parent 31d22c7 commit 4241954

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

xds/internal/balancer/lrs/lrs_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"google.golang.org/grpc/codes"
4040
"google.golang.org/grpc/status"
4141
"google.golang.org/grpc/xds/internal"
42+
"google.golang.org/grpc/xds/internal/testutils"
4243
)
4344

4445
const (
@@ -286,7 +287,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) {
286287
)
287288
}
288289
upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{
289-
Locality: l.ToProto(),
290+
Locality: testutils.LocalityIDToProto(l),
290291
TotalSuccessfulRequests: count.success,
291292
TotalRequestsInProgress: tempInProgress,
292293
TotalErrorRequests: count.failure,
@@ -298,7 +299,7 @@ func Test_lrsStore_buildStats_rpcCounts(t *testing.T) {
298299
for l, c := range inProgressCounts {
299300
if _, ok := counts[l]; !ok {
300301
upstreamLocalityStats = append(upstreamLocalityStats, &endpointpb.UpstreamLocalityStats{
301-
Locality: l.ToProto(),
302+
Locality: testutils.LocalityIDToProto(l),
302303
TotalRequestsInProgress: c,
303304
})
304305
}

xds/internal/internal.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ package internal
2121

2222
import (
2323
"fmt"
24-
25-
corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
2624
)
2725

2826
type clientID string
@@ -49,12 +47,3 @@ type LocalityID struct {
4947
func (l LocalityID) String() string {
5048
return fmt.Sprintf("%s-%s-%s", l.Region, l.Zone, l.SubZone)
5149
}
52-
53-
// ToProto convert Locality to the proto representation.
54-
func (l LocalityID) ToProto() *corepb.Locality {
55-
return &corepb.Locality{
56-
Region: l.Region,
57-
Zone: l.Zone,
58-
SubZone: l.SubZone,
59-
}
60-
}

xds/internal/testutils/locality.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* Copyright 2020 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
19+
20+
import (
21+
corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
22+
"google.golang.org/grpc/xds/internal"
23+
)
24+
25+
// LocalityIDToProto converts a LocalityID to its proto representation.
26+
func LocalityIDToProto(l internal.LocalityID) *corepb.Locality {
27+
return &corepb.Locality{
28+
Region: l.Region,
29+
Zone: l.Zone,
30+
SubZone: l.SubZone,
31+
}
32+
}

0 commit comments

Comments
 (0)