UTs for pkg/kubectl generate_test.go

This commit is contained in:
m1093782566
2017-08-03 10:16:57 +08:00
parent 2495cc602f
commit 3bf8fc3a57
2 changed files with 249 additions and 0 deletions

View File

@@ -159,6 +159,12 @@ func ParseProtocols(protocols interface{}) (map[string]string, error) {
if len(portProtocol) != 2 {
return nil, fmt.Errorf("unexpected port protocol mapping: %s", protocolsSlice[ix])
}
if len(portProtocol[0]) == 0 {
return nil, fmt.Errorf("unexpected empty port")
}
if len(portProtocol[1]) == 0 {
return nil, fmt.Errorf("unexpected empty protocol")
}
portProtocolMap[portProtocol[0]] = portProtocol[1]
}
return portProtocolMap, nil
@@ -188,6 +194,9 @@ func ParseLabels(labelSpec interface{}) (map[string]string, error) {
if len(labelSpec) != 2 {
return nil, fmt.Errorf("unexpected label spec: %s", labelSpecs[ix])
}
if len(labelSpec[0]) == 0 {
return nil, fmt.Errorf("unexpected empty label key")
}
labels[labelSpec[0]] = labelSpec[1]
}
return labels, nil