Lint on pkg/* packages
- pkg/useragent - pkg/units - pkg/ulimit - pkg/truncindex - pkg/timeoutconn - pkg/term - pkg/tarsum - pkg/tailfile - pkg/systemd - pkg/stringutils - pkg/stringid - pkg/streamformatter - pkg/sockets - pkg/signal - pkg/proxy - pkg/progressreader - pkg/pools - pkg/plugins - pkg/pidfile - pkg/parsers - pkg/parsers/filters - pkg/parsers/kernel - pkg/parsers/operatingsystem Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
a922d62168
commit
9bcb3cba83
56 changed files with 455 additions and 195 deletions
|
@ -1,3 +1,4 @@
|
|||
// Package stringutils provides helper functions for dealing with strings.
|
||||
package stringutils
|
||||
|
||||
import (
|
||||
|
@ -8,7 +9,7 @@ import (
|
|||
"github.com/docker/docker/pkg/random"
|
||||
)
|
||||
|
||||
// Generate alpha only random stirng with length n
|
||||
// GenerateRandomAlphaOnlyString generates an alphabetical random string with length n.
|
||||
func GenerateRandomAlphaOnlyString(n int) string {
|
||||
// make a really long string
|
||||
letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
@ -20,8 +21,8 @@ func GenerateRandomAlphaOnlyString(n int) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
// Generate Ascii random stirng with length n
|
||||
func GenerateRandomAsciiString(n int) string {
|
||||
// GenerateRandomASCIIString generates an ASCII random stirng with length n.
|
||||
func GenerateRandomASCIIString(n int) string {
|
||||
chars := "abcdefghijklmnopqrstuvwxyz" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
|
||||
"~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:` "
|
||||
|
@ -32,7 +33,7 @@ func GenerateRandomAsciiString(n int) string {
|
|||
return string(res)
|
||||
}
|
||||
|
||||
// Truncate a string to maxlen
|
||||
// Truncate truncates a string to maxlen.
|
||||
func Truncate(s string, maxlen int) string {
|
||||
if len(s) <= maxlen {
|
||||
return s
|
||||
|
@ -40,7 +41,7 @@ func Truncate(s string, maxlen int) string {
|
|||
return s[:maxlen]
|
||||
}
|
||||
|
||||
// Test wheather a string is contained in a slice of strings or not.
|
||||
// InSlice tests whether a string is contained in a slice of strings or not.
|
||||
// Comparison is case insensitive
|
||||
func InSlice(slice []string, s string) bool {
|
||||
for _, ss := range slice {
|
||||
|
@ -73,8 +74,8 @@ func quote(word string, buf *bytes.Buffer) {
|
|||
buf.WriteString("'")
|
||||
}
|
||||
|
||||
// Take a list of strings and escape them so they will be handled right
|
||||
// when passed as arguments to an program via a shell
|
||||
// ShellQuoteArguments takes a list of strings and escapes them so they will be
|
||||
// handled right when passed as arguments to an program via a shell
|
||||
func ShellQuoteArguments(args []string) string {
|
||||
var buf bytes.Buffer
|
||||
for i, arg := range args {
|
||||
|
|
|
@ -43,15 +43,15 @@ func TestGenerateRandomAlphaOnlyStringUniqueness(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGenerateRandomAsciiStringLength(t *testing.T) {
|
||||
testLengthHelper(GenerateRandomAsciiString, t)
|
||||
testLengthHelper(GenerateRandomASCIIString, t)
|
||||
}
|
||||
|
||||
func TestGenerateRandomAsciiStringUniqueness(t *testing.T) {
|
||||
testUniquenessHelper(GenerateRandomAsciiString, t)
|
||||
testUniquenessHelper(GenerateRandomASCIIString, t)
|
||||
}
|
||||
|
||||
func TestGenerateRandomAsciiStringIsAscii(t *testing.T) {
|
||||
str := GenerateRandomAsciiString(64)
|
||||
str := GenerateRandomASCIIString(64)
|
||||
if !isASCII(str) {
|
||||
t.Fatalf("%s contained non-ascii characters", str)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue