Skip to content

Commit 0e8936d

Browse files
Add extra tests for DNS and prepare for Headless services
1 parent 3dfe92b commit 0e8936d

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

test/integration/dns_test.go

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
package integration
44

55
import (
6+
"net"
67
"testing"
78
"time"
89

10+
//kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
911
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
1012

1113
"github.com/miekg/dns"
@@ -18,6 +20,8 @@ func TestDNS(t *testing.T) {
1820
t.Fatalf("unexpected error: %v", err)
1921
}
2022

23+
var masterIP net.IP
24+
2125
// verify service DNS entry is visible
2226
stop := make(chan struct{})
2327
util.Until(func() {
@@ -36,24 +40,68 @@ func TestDNS(t *testing.T) {
3640
}
3741
if a, ok := in.Answer[0].(*dns.A); ok {
3842
if a.A == nil {
39-
t.Errorf("expected an A record with an IP: %#v", a)
43+
t.Fatalf("expected an A record with an IP: %#v", a)
4044
}
45+
masterIP = a.A
4146
} else {
42-
t.Errorf("expected an A record: %#v", in)
47+
t.Fatalf("expected an A record: %#v", in)
4348
}
4449
t.Log(in)
4550
close(stop)
4651
}, 50*time.Millisecond, stop)
4752

53+
// TODO: uncomment when headless services are supported
54+
/*client, err := testutil.GetClusterAdminKubeClient(clientFile)
55+
if err != nil {
56+
t.Fatalf("unexpected error: %v", err)
57+
}
58+
if _, err := client.Services(kapi.NamespaceDefault).Create(&kapi.Service{
59+
ObjectMeta: kapi.ObjectMeta{
60+
Name: "headless",
61+
},
62+
Spec: kapi.ServiceSpec{
63+
PortalIP: "None",
64+
Port: 443,
65+
},
66+
}); err != nil {
67+
t.Fatalf("unexpected error: %v", err)
68+
}
69+
if _, err := client.Endpoints(kapi.NamespaceDefault).Create(&kapi.Endpoints{
70+
ObjectMeta: kapi.ObjectMeta{
71+
Name: "headless",
72+
},
73+
Endpoints: []kapi.Endpoint{
74+
{
75+
IP: "172.0.0.1",
76+
Port: 2345,
77+
},
78+
},
79+
}); err != nil {
80+
t.Fatalf("unexpected error: %v", err)
81+
}
82+
headlessIP := net.ParseIP("172.0.0.1")*/
83+
4884
// verify recursive DNS lookup is visible when expected
4985
tests := []struct {
5086
dnsQuestionName string
5187
recursionExpected bool
88+
expect *net.IP
5289
}{
5390
{
5491
dnsQuestionName: "foo.kubernetes.default.local.",
5592
recursionExpected: false,
93+
expect: &masterIP,
5694
},
95+
{
96+
dnsQuestionName: "openshift.default.local.",
97+
recursionExpected: false,
98+
expect: &masterIP,
99+
},
100+
/*{
101+
dnsQuestionName: "headless.default.local.",
102+
recursionExpected: false,
103+
expect: &headlessIP,
104+
},*/
57105
{
58106
dnsQuestionName: "www.google.com.",
59107
recursionExpected: true,
@@ -76,6 +124,10 @@ func TestDNS(t *testing.T) {
76124
if a, ok := in.Answer[0].(*dns.A); ok {
77125
if a.A == nil {
78126
t.Errorf("expected an A record with an IP: %#v", a)
127+
} else {
128+
if tc.expect != nil && tc.expect.String() != a.A.String() {
129+
t.Errorf("A record has a different IP than the test case: %v / %v", a.A, *tc.expect)
130+
}
79131
}
80132
} else {
81133
t.Errorf("expected an A record: %#v", in)

0 commit comments

Comments
 (0)