Skip to content

Commit

Permalink
code review: avoid exporting getCommonProtocol function
Browse files Browse the repository at this point in the history
  • Loading branch information
yskopets committed Feb 17, 2020
1 parent e3ddf95 commit 0c06b96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/xds/generator/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var (
}
)

// GetCommonProtocol returns a common protocol between given two.
// getCommonProtocol returns a common protocol between given two.
//
// E.g.,
// a common protocol between HTTP and HTTP is HTTP,
// a common protocol between HTTP and TCP is TCP,
// a common protocol between GRPC and HTTP2 is HTTP2,
// a common protocol between HTTP and HTTP2 is TCP.
func GetCommonProtocol(one, another mesh_core.Protocol) mesh_core.Protocol {
func getCommonProtocol(one, another mesh_core.Protocol) mesh_core.Protocol {
if one == another {
return one
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func InferServiceProtocol(endpoints []core_xds.Endpoint) mesh_core.Protocol {
serviceProtocol := mesh_core.ParseProtocol(endpoints[0].Tags[mesh_proto.ProtocolTag])
for _, endpoint := range endpoints[1:] {
endpointProtocol := mesh_core.ParseProtocol(endpoint.Tags[mesh_proto.ProtocolTag])
serviceProtocol = GetCommonProtocol(serviceProtocol, endpointProtocol)
serviceProtocol = getCommonProtocol(serviceProtocol, endpointProtocol)
}
return serviceProtocol
}
5 changes: 5 additions & 0 deletions pkg/xds/generator/protocol_helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package generator

// GetCommonProtocol is an alias for function getCommonProtocol
// that is accessible to unit tests in generator_test package.
var GetCommonProtocol = getCommonProtocol
2 changes: 1 addition & 1 deletion pkg/xds/generator/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
core_xds "github.com/Kong/kuma/pkg/core/xds"
)

var _ = Describe("GetCommonProtocol()", func() {
var _ = Describe("getCommonProtocol()", func() {
type testCase struct {
one mesh_core.Protocol
another mesh_core.Protocol
Expand Down

0 comments on commit 0c06b96

Please sign in to comment.