gorealis/vendor/github.com/samuel/go-zookeeper/zk/util_test.go
Renan DelValle 8d445c1c77
Moving from govendor to dep, updated dependencies (#48)
* Moving from govendor to dep.

* Making the pull request template more friendly.

* Fixing akward space in PR template.

* goimports run on whole project using ` goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./gen-go/*")`

source of command: https://gist.github.com/bgentry/fd1ffef7dbde01857f66
2018-01-07 13:13:47 -08:00

53 lines
1.4 KiB
Go

package zk
import "testing"
func TestFormatServers(t *testing.T) {
t.Parallel()
servers := []string{"127.0.0.1:2181", "127.0.0.42", "127.0.42.1:8811"}
r := []string{"127.0.0.1:2181", "127.0.0.42:2181", "127.0.42.1:8811"}
for i, s := range FormatServers(servers) {
if s != r[i] {
t.Errorf("%v should equal %v", s, r[i])
}
}
}
func TestValidatePath(t *testing.T) {
tt := []struct {
path string
seq bool
valid bool
}{
{"/this is / a valid/path", false, true},
{"/", false, true},
{"", false, false},
{"not/valid", false, false},
{"/ends/with/slash/", false, false},
{"/sequential/", true, true},
{"/test\u0000", false, false},
{"/double//slash", false, false},
{"/single/./period", false, false},
{"/double/../period", false, false},
{"/double/..ok/period", false, true},
{"/double/alsook../period", false, true},
{"/double/period/at/end/..", false, false},
{"/name/with.period", false, true},
{"/test\u0001", false, false},
{"/test\u001f", false, false},
{"/test\u0020", false, true}, // first allowable
{"/test\u007e", false, true}, // last valid ascii
{"/test\u007f", false, false},
{"/test\u009f", false, false},
{"/test\uf8ff", false, false},
{"/test\uffef", false, true},
{"/test\ufff0", false, false},
}
for _, tc := range tt {
err := validatePath(tc.path, tc.seq)
if (err != nil) == tc.valid {
t.Errorf("failed to validate path %q", tc.path)
}
}
}