Merge pull request #69491 from chrischdi/lint-pkg-util-strings

fix golint errors in pkg/util/strings
This commit is contained in:
k8s-ci-robot 2018-10-11 18:26:43 -07:00 committed by GitHub
commit 3dbb1481f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View File

@ -397,7 +397,6 @@ pkg/util/removeall
pkg/util/resourcecontainer pkg/util/resourcecontainer
pkg/util/rlimit pkg/util/rlimit
pkg/util/selinux pkg/util/selinux
pkg/util/strings
pkg/util/sysctl pkg/util/sysctl
pkg/util/sysctl/testing pkg/util/sysctl/testing
pkg/util/system pkg/util/system

View File

@ -22,7 +22,7 @@ import (
"unicode" "unicode"
) )
// Splits a fully qualified name and returns its namespace and name. // SplitQualifiedName Splits a fully qualified name and returns its namespace and name.
// Assumes that the input 'str' has been validated. // Assumes that the input 'str' has been validated.
func SplitQualifiedName(str string) (string, string) { func SplitQualifiedName(str string) (string, string) {
parts := strings.Split(str, "/") parts := strings.Split(str, "/")
@ -32,19 +32,18 @@ func SplitQualifiedName(str string) (string, string) {
return parts[0], parts[1] return parts[0], parts[1]
} }
// Joins 'namespace' and 'name' and returns a fully qualified name // JoinQualifiedName joins 'namespace' and 'name' and returns a fully qualified name
// Assumes that the input is valid. // Assumes that the input is valid.
func JoinQualifiedName(namespace, name string) string { func JoinQualifiedName(namespace, name string) string {
return path.Join(namespace, name) return path.Join(namespace, name)
} }
// Returns the first N slice of a string. // ShortenString returns the first N slice of a string.
func ShortenString(str string, n int) string { func ShortenString(str string, n int) string {
if len(str) <= n { if len(str) <= n {
return str return str
} else {
return str[:n]
} }
return str[:n]
} }
// isVowel returns true if the rune is a vowel (case insensitive). // isVowel returns true if the rune is a vowel (case insensitive).

View File

@ -56,16 +56,16 @@ func TestJoinQualifiedName(t *testing.T) {
func TestShortenString(t *testing.T) { func TestShortenString(t *testing.T) {
testCases := []struct { testCases := []struct {
input string input string
out_len int outLen int
output string output string
}{ }{
{"kubernetes.io", 5, "kuber"}, {"kubernetes.io", 5, "kuber"},
{"blah", 34, "blah"}, {"blah", 34, "blah"},
{"kubernetes.io", 13, "kubernetes.io"}, {"kubernetes.io", 13, "kubernetes.io"},
} }
for i, tc := range testCases { for i, tc := range testCases {
res := ShortenString(tc.input, tc.out_len) res := ShortenString(tc.input, tc.outLen)
if res != tc.output { if res != tc.output {
t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res) t.Errorf("case[%d]: expected %q, got %q", i, tc.output, res)
} }