2014-02-11 21:46:55 -05:00
|
|
|
package opts
|
2013-12-02 17:33:33 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-07-09 17:47:55 -04:00
|
|
|
func TestValidateIPAddress(t *testing.T) {
|
|
|
|
if ret, err := ValidateIPAddress(`1.2.3.4`); err != nil || ret == "" {
|
|
|
|
t.Fatalf("ValidateIPAddress(`1.2.3.4`) got %s %s", ret, err)
|
2013-12-02 17:33:33 -05:00
|
|
|
}
|
|
|
|
|
2014-07-09 17:47:55 -04:00
|
|
|
if ret, err := ValidateIPAddress(`127.0.0.1`); err != nil || ret == "" {
|
|
|
|
t.Fatalf("ValidateIPAddress(`127.0.0.1`) got %s %s", ret, err)
|
2013-12-02 17:33:33 -05:00
|
|
|
}
|
|
|
|
|
2014-07-09 17:47:55 -04:00
|
|
|
if ret, err := ValidateIPAddress(`::1`); err != nil || ret == "" {
|
|
|
|
t.Fatalf("ValidateIPAddress(`::1`) got %s %s", ret, err)
|
2013-12-02 17:33:33 -05:00
|
|
|
}
|
|
|
|
|
2014-07-09 17:47:55 -04:00
|
|
|
if ret, err := ValidateIPAddress(`127`); err == nil || ret != "" {
|
|
|
|
t.Fatalf("ValidateIPAddress(`127`) got %s %s", ret, err)
|
2014-06-13 08:02:12 -04:00
|
|
|
}
|
|
|
|
|
2014-07-09 17:47:55 -04:00
|
|
|
if ret, err := ValidateIPAddress(`random invalid string`); err == nil || ret != "" {
|
|
|
|
t.Fatalf("ValidateIPAddress(`random invalid string`) got %s %s", ret, err)
|
2013-12-02 17:33:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-07 11:48:14 -05:00
|
|
|
|
2014-08-09 21:13:44 -04:00
|
|
|
func TestListOpts(t *testing.T) {
|
|
|
|
o := NewListOpts(nil)
|
|
|
|
o.Set("foo")
|
|
|
|
o.String()
|
|
|
|
}
|
|
|
|
|
2014-06-26 07:03:23 -04:00
|
|
|
func TestValidateDnsSearch(t *testing.T) {
|
2014-02-07 11:48:14 -05:00
|
|
|
valid := []string{
|
2014-06-26 07:03:23 -04:00
|
|
|
`.`,
|
2014-02-07 11:48:14 -05:00
|
|
|
`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{
|
|
|
|
``,
|
2014-06-26 07:03:23 -04:00
|
|
|
` `,
|
|
|
|
` `,
|
2014-02-07 11:48:14 -05:00
|
|
|
`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 {
|
2014-06-26 07:03:23 -04:00
|
|
|
if ret, err := ValidateDnsSearch(domain); err != nil || ret == "" {
|
|
|
|
t.Fatalf("ValidateDnsSearch(`"+domain+"`) got %s %s", ret, err)
|
2014-02-07 11:48:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, domain := range invalid {
|
2014-06-26 07:03:23 -04:00
|
|
|
if ret, err := ValidateDnsSearch(domain); err == nil || ret != "" {
|
|
|
|
t.Fatalf("ValidateDnsSearch(`"+domain+"`) got %s %s", ret, err)
|
2014-02-07 11:48:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|