1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/opts/opts_test.go
Daniel Norberg fbfac21ed4 configurable dns search domains
Add a --dns-search parameter and a DnsSearch
configuration field for specifying dns search
domains.

Docker-DCO-1.1-Signed-off-by: Daniel Norberg <daniel.norberg@gmail.com> (github: danielnorberg)
2014-03-19 10:49:25 -04:00

78 lines
1.5 KiB
Go

package opts
import (
"testing"
)
func TestValidateIP4(t *testing.T) {
if ret, err := ValidateIp4Address(`1.2.3.4`); err != nil || ret == "" {
t.Fatalf("ValidateIp4Address(`1.2.3.4`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`127.0.0.1`); err != nil || ret == "" {
t.Fatalf("ValidateIp4Address(`127.0.0.1`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`127`); err == nil || ret != "" {
t.Fatalf("ValidateIp4Address(`127`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`random invalid string`); err == nil || ret != "" {
t.Fatalf("ValidateIp4Address(`random invalid string`) got %s %s", ret, err)
}
}
func TestValidateDomain(t *testing.T) {
valid := []string{
`a`,
`a.`,
`1.foo`,
`17.foo`,
`foo.bar`,
`foo.bar.baz`,
`foo.bar.`,
`foo.bar.baz`,
`foo1.bar2`,
`foo1.bar2.baz`,
`1foo.2bar.`,
`1foo.2bar.baz`,
`foo-1.bar-2`,
`foo-1.bar-2.baz`,
`foo-1.bar-2.`,
`foo-1.bar-2.baz`,
`1-foo.2-bar`,
`1-foo.2-bar.baz`,
`1-foo.2-bar.`,
`1-foo.2-bar.baz`,
}
invalid := []string{
``,
`.`,
`17`,
`17.`,
`.17`,
`17-.`,
`17-.foo`,
`.foo`,
`foo-.bar`,
`-foo.bar`,
`foo.bar-`,
`foo.bar-.baz`,
`foo.-bar`,
`foo.-bar.baz`,
}
for _, domain := range valid {
if ret, err := ValidateDomain(domain); err != nil || ret == "" {
t.Fatalf("ValidateDomain(`"+domain+"`) got %s %s", ret, err)
}
}
for _, domain := range invalid {
if ret, err := ValidateDomain(domain); err == nil || ret != "" {
t.Fatalf("ValidateDomain(`"+domain+"`) got %s %s", ret, err)
}
}
}