Skip to content

Commit

Permalink
Added case for lowercase protocol (kedgeproject#564)
Browse files Browse the repository at this point in the history
This will accept if someone specifies protocol as
tcp or Tcp or tCp. Likewise UDP also
Always return the protocol as Uppercase
Added test for two cases

changed variable name to CamelCase
  • Loading branch information
Piyush Garg authored and kadel committed Jan 17, 2018
1 parent 63a88cf commit 1f01e39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/spec/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,10 @@ func parsePortMapping(pm string) (*api_v1.ServicePort, error) {
// Case 3 - port/protocol
// Case 4 - port:targetPort/protocol
case 2:
switch api_v1.Protocol(protocolSplit[1]) {
protocolUpperCase := strings.ToUpper(protocolSplit[1])
switch api_v1.Protocol(protocolUpperCase) {
case api_v1.ProtocolTCP, api_v1.ProtocolUDP:
protocol = api_v1.Protocol(protocolSplit[1])
protocol = api_v1.Protocol(protocolUpperCase)
default:
return nil, fmt.Errorf("invalid protocol '%v' provided, the acceptable values are '%v' and '%v'", protocolSplit[1], api.ProtocolTCP, api.ProtocolUDP)
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/spec/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,30 @@ func TestParsePortMapping(t *testing.T) {
},
success: true,
},
{
name: "port/protocol(lowercase) is passed",
portMapping: "1337/udp",
servicePort: &api_v1.ServicePort{
Port: 1337,
TargetPort: intstr.IntOrString{
IntVal: 1337,
},
Protocol: api_v1.ProtocolUDP,
},
success: true,
},
{
name: "port/protocol(tCp) is passed",
portMapping: "1337/tCp",
servicePort: &api_v1.ServicePort{
Port: 1337,
TargetPort: intstr.IntOrString{
IntVal: 1337,
},
Protocol: api_v1.ProtocolTCP,
},
success: true,
},
{
name: "port:targetPort/protocol is passed",
portMapping: "1337:1338/UDP",
Expand Down

0 comments on commit 1f01e39

Please sign in to comment.