Add helper for lowercase list of strings

This commit is contained in:
William Tisäter 2014-07-17 08:37:25 +02:00
parent 436cd144a5
commit e5798c74d2
2 changed files with 18 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"github.com/hashicorp/serf/serf"
)
@ -68,6 +69,14 @@ func strContains(l []string, s string) bool {
return false
}
func ToLowerList(l []string) []string {
var out []string
for _, value := range l {
out = append(out, strings.ToLower(value))
}
return out
}
// ensurePath is used to make sure a path exists
func ensurePath(path string, dir bool) error {
if !dir {

View File

@ -18,6 +18,15 @@ func TestStrContains(t *testing.T) {
}
}
func TestToLowerList(t *testing.T) {
l := []string{"ABC", "Abc", "abc"}
for _, value := range ToLowerList(l) {
if value != "abc" {
t.Fatalf("failed lowercasing")
}
}
}
func TestIsPrivateIP(t *testing.T) {
if !isPrivateIP("192.168.1.1") {
t.Fatalf("bad")