@@ -12,22 +12,19 @@ import (
12
12
)
13
13
14
14
func TestDNS (t * testing.T ) {
15
- _ , err := StartTestAllInOne ()
15
+ masterConfig , _ , err := StartTestAllInOne ()
16
16
if err != nil {
17
17
t .Fatalf ("unexpected error: %v" , err )
18
18
}
19
19
20
- // ugly...
21
- server := "127.0.0.1:8053"
22
-
23
20
// verify service DNS entry is visible
24
21
stop := make (chan struct {})
25
22
util .Until (func () {
26
23
m1 := & dns.Msg {
27
24
MsgHdr : dns.MsgHdr {Id : dns .Id (), RecursionDesired : true },
28
25
Question : []dns.Question {{"kubernetes.default.local." , dns .TypeA , dns .ClassINET }},
29
26
}
30
- in , err := dns .Exchange (m1 , server )
27
+ in , err := dns .Exchange (m1 , masterConfig . DNSConfig . BindAddress )
31
28
if err != nil {
32
29
t .Logf ("unexpected error: %v" , err )
33
30
return
@@ -47,45 +44,36 @@ func TestDNS(t *testing.T) {
47
44
close (stop )
48
45
}, 50 * time .Millisecond , stop )
49
46
50
- // verify recursive DNS lookup is visible
51
- m1 := & dns.Msg {
52
- MsgHdr : dns.MsgHdr {Id : dns .Id (), RecursionDesired : true },
53
- Question : []dns.Question {{"foo.kubernetes.default.local." , dns .TypeA , dns .ClassINET }},
54
- }
55
- in , err := dns .Exchange (m1 , server )
56
- if err != nil {
57
- t .Fatalf ("unexpected error: %v" , err )
58
- }
59
- if len (in .Answer ) != 1 {
60
- t .Fatalf ("unexpected response: %#v" , in )
47
+ //verify recursive DNS lookup visible
48
+ tests := []struct {
49
+ dnsQuestionName string
50
+ }{
51
+ {
52
+ dnsQuestionName : "foo.kubernetes.default.local." ,
53
+ },
54
+ {
55
+ dnsQuestionName : "www.google.com." ,
56
+ },
61
57
}
62
- if a , ok := in .Answer [0 ].(* dns.A ); ok {
63
- if a .A == nil {
64
- t .Errorf ("expected an A record with an IP: %#v" , a )
58
+ for _ , tc := range tests {
59
+ m1 := & dns.Msg {
60
+ MsgHdr : dns.MsgHdr {Id : dns .Id (), RecursionDesired : true },
61
+ Question : []dns.Question {{tc .dnsQuestionName , dns .TypeA , dns .ClassINET }},
65
62
}
66
- } else {
67
- t .Errorf ("expected an A record: %#v" , in )
68
- }
69
- t .Log (in )
70
-
71
- // verify recursive DNS lookup is visible
72
- m1 = & dns.Msg {
73
- MsgHdr : dns.MsgHdr {Id : dns .Id (), RecursionDesired : true },
74
- Question : []dns.Question {{"www.google.com." , dns .TypeA , dns .ClassINET }},
75
- }
76
- in , err = dns .Exchange (m1 , server )
77
- if err != nil {
78
- t .Fatalf ("unexpected error: %v" , err )
79
- }
80
- if len (in .Answer ) == 0 {
81
- t .Fatalf ("unexpected response: %#v" , in )
82
- }
83
- if a , ok := in .Answer [0 ].(* dns.A ); ok {
84
- if a .A == nil {
85
- t .Errorf ("expected an A record with an IP: %#v" , a )
63
+ in , err := dns .Exchange (m1 , masterConfig .DNSConfig .BindAddress )
64
+ if err != nil {
65
+ t .Fatalf ("unexpected error: %v" , err )
66
+ }
67
+ if len (in .Answer ) < 1 {
68
+ t .Fatalf ("unexpected response: %#v" , in )
69
+ }
70
+ if a , ok := in .Answer [0 ].(* dns.A ); ok {
71
+ if a .A == nil {
72
+ t .Errorf ("expected an A record with an IP: %#v" , a )
73
+ }
74
+ } else {
75
+ t .Errorf ("expected an A record: %#v" , in )
86
76
}
87
- } else {
88
- t .Errorf ("expected an A record: %#v" , in )
77
+ t .Log (in )
89
78
}
90
- t .Log (in )
91
79
}
0 commit comments