1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 type testCase
struct {
17 var tests
= []testCase
{
18 // RFC2181, section 11.
19 {"_xmpp-server._tcp.google.com", true},
22 {"26.0.0.73.com", true},
33 func getTestCases(ch
chan<- testCase
) {
38 for i
:= 0; i
< 59; i
++ {
41 char63
= char59
+ "aaaa"
44 for _
, tc
:= range tests
{
48 ch
<- testCase
{char63
+ ".com", true}
49 ch
<- testCase
{char64
+ ".com", false}
50 // 255 char name is fine:
51 ch
<- testCase
{char59
+ "." + char63
+ "." + char63
+ "." +
54 // 256 char name is bad:
55 ch
<- testCase
{char59
+ "a." + char63
+ "." + char63
+ "." +
60 func TestDNSNames(t
*testing
.T
) {
61 ch
:= make(chan testCase
)
64 if isDomainName(tc
.name
) != tc
.result
{
65 t
.Errorf("isDomainName(%v) failed: Should be %v",
71 func BenchmarkDNSNames(b
*testing
.B
) {
72 benchmarks
:= append(tests
, []testCase
{
73 {strings
.Repeat("a", 63), true},
74 {strings
.Repeat("a", 64), false},
76 for n
:= 0; n
< b
.N
; n
++ {
77 for _
, tc
:= range benchmarks
{
78 if isDomainName(tc
.name
) != tc
.result
{
79 b
.Errorf("isDomainName(%q) = %v; want %v", tc
.name
, !tc
.result
, tc
.result
)