Skip to content

Commit 17a5def

Browse files
committed
Test for DNS resolution on Mac
1 parent bd15020 commit 17a5def

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

pkg/minikube/tunnel/route_darwin_test.go

+28-7
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ func TestDarwinRouteFailsOnConflictIntegrationTest(t *testing.T) {
3535
IP: net.IPv4(10, 96, 0, 0),
3636
Mask: net.IPv4Mask(255, 240, 0, 0),
3737
},
38+
ClusterDomain: "cluster.local",
39+
ClusterDNSIP: net.IPv4(10, 96, 0, 10),
3840
}
41+
conflictingCfg := *cfg
42+
conflictingCfg.Gateway = net.IPv4(127, 0, 0, 2)
3943

40-
addRoute(t, "10.96.0.0/12", "127.0.0.2")
44+
addRoute(t, &conflictingCfg)
45+
defer cleanRoute(t, &conflictingCfg)
4146
err := (&osRouter{}).EnsureRouteIsAdded(cfg)
4247
if err == nil {
4348
t.Errorf("add should have error, but it is nil")
@@ -51,9 +56,11 @@ func TestDarwinRouteIdempotentIntegrationTest(t *testing.T) {
5156
IP: net.IPv4(10, 96, 0, 0),
5257
Mask: net.IPv4Mask(255, 240, 0, 0),
5358
},
59+
ClusterDomain: "cluster.local",
60+
ClusterDNSIP: net.IPv4(10, 96, 0, 10),
5461
}
5562

56-
cleanRoute(t, "10.96.0.0/12")
63+
cleanRoute(t, cfg)
5764
err := (&osRouter{}).EnsureRouteIsAdded(cfg)
5865
if err != nil {
5966
t.Errorf("add error: %s", err)
@@ -64,7 +71,7 @@ func TestDarwinRouteIdempotentIntegrationTest(t *testing.T) {
6471
t.Errorf("add error: %s", err)
6572
}
6673

67-
cleanRoute(t, "10.96.0.0/12")
74+
cleanRoute(t, cfg)
6875
}
6976

7077
func TestDarwinRouteCleanupIdempontentIntegrationTest(t *testing.T) {
@@ -75,10 +82,12 @@ func TestDarwinRouteCleanupIdempontentIntegrationTest(t *testing.T) {
7582
IP: net.IPv4(10, 96, 0, 0),
7683
Mask: net.IPv4Mask(255, 240, 0, 0),
7784
},
85+
ClusterDomain: "cluster.local",
86+
ClusterDNSIP: net.IPv4(10, 96, 0, 10),
7887
}
7988

80-
cleanRoute(t, "10.96.0.0/12")
81-
addRoute(t, "10.96.0.0/12", "192.168.1.1")
89+
cleanRoute(t, cfg)
90+
addRoute(t, cfg)
8291
err := (&osRouter{}).Cleanup(cfg)
8392
if err != nil {
8493
t.Errorf("cleanup failed with %s", err)
@@ -89,20 +98,32 @@ func TestDarwinRouteCleanupIdempontentIntegrationTest(t *testing.T) {
8998
}
9099
}
91100

92-
func addRoute(t *testing.T, cidr string, gw string) {
101+
func addRoute(t *testing.T, r *Route) {
102+
cidr := r.DestCIDR.String()
103+
gw := r.Gateway.String()
93104
command := exec.Command("sudo", "route", "-n", "add", cidr, gw)
94105
_, err := command.CombinedOutput()
95106
if err != nil {
96107
t.Logf("add route error (should be ok): %s", err)
97108
}
109+
err = writeResolverFile(r)
110+
if err != nil {
111+
t.Logf("add route DNS resolver error (should be ok): %s", err)
112+
}
98113
}
99114

100-
func cleanRoute(t *testing.T, cidr string) {
115+
func cleanRoute(t *testing.T, r *Route) {
116+
cidr := r.DestCIDR.String()
101117
command := exec.Command("sudo", "route", "-n", "delete", cidr)
102118
_, err := command.CombinedOutput()
103119
if err != nil {
104120
t.Logf("cleanup error (should be ok): %s", err)
105121
}
122+
command := exec.Command("sudo", "rm", "-f", fmt.Sprintf("/etc/resolver/%s", r.ClusterDomain))
123+
_, err := command.CombinedOutput()
124+
if err != nil {
125+
t.Logf("cleanup DNS resolver error (should be ok): %s", err)
126+
}
106127
}
107128

108129
func TestCIDRPadding(t *testing.T) {

0 commit comments

Comments
 (0)