Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix golint errors in pkg/util/strings #69491

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.golint_failures
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ pkg/util/removeall
pkg/util/resourcecontainer
pkg/util/rlimit
pkg/util/selinux
pkg/util/strings
pkg/util/sysctl
pkg/util/sysctl/testing
pkg/util/system
Expand Down
9 changes: 4 additions & 5 deletions pkg/util/strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"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.
func SplitQualifiedName(str string) (string, string) {
parts := strings.Split(str, "/")
Expand All @@ -32,19 +32,18 @@ func SplitQualifiedName(str string) (string, string) {
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.
func JoinQualifiedName(namespace, name string) string {
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 {
if len(str) <= n {
return str
} else {
return str[:n]
}
return str[:n]
}

// isVowel returns true if the rune is a vowel (case insensitive).
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/strings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ func TestJoinQualifiedName(t *testing.T) {

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