Add DNS integration tests

This commit is contained in:
Tatsuhiro Tsujikawa 2016-12-11 11:32:38 +09:00
parent c487cd888f
commit e007b6b031
2 changed files with 96 additions and 3 deletions

View File

@ -1369,6 +1369,42 @@ func TestH2H1ProxyProtocolV1InvalidID(t *testing.T) {
} }
} }
// TestH2H1ExternalDNS tests that DNS resolution using external DNS
// with HTTP/1 backend works.
func TestH2H1ExternalDNS(t *testing.T) {
st := newServerTester([]string{"--external-dns"}, t, noopHandler)
defer st.Close()
res, err := st.http2(requestParam{
name: "TestH2H1ExternalDNS",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
if got, want := res.status, 200; got != want {
t.Errorf("status = %v; want %v", got, want)
}
}
// TestH2H1DNS tests that DNS resolution without external DNS with
// HTTP/1 backend works.
func TestH2H1DNS(t *testing.T) {
st := newServerTester([]string{"--dns"}, t, noopHandler)
defer st.Close()
res, err := st.http2(requestParam{
name: "TestH2H1DNS",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
if got, want := res.status, 200; got != want {
t.Errorf("status = %v; want %v", got, want)
}
}
// TestH2H1GracefulShutdown tests graceful shutdown. // TestH2H1GracefulShutdown tests graceful shutdown.
func TestH2H1GracefulShutdown(t *testing.T) { func TestH2H1GracefulShutdown(t *testing.T) {
st := newServerTester(nil, t, noopHandler) st := newServerTester(nil, t, noopHandler)
@ -1845,6 +1881,42 @@ func TestH2H2RespPhaseReturn(t *testing.T) {
} }
} }
// TestH2H2ExternalDNS tests that DNS resolution using external DNS
// with HTTP/2 backend works.
func TestH2H2ExternalDNS(t *testing.T) {
st := newServerTester([]string{"--http2-bridge", "--external-dns"}, t, noopHandler)
defer st.Close()
res, err := st.http2(requestParam{
name: "TestH2H2ExternalDNS",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
if got, want := res.status, 200; got != want {
t.Errorf("status = %v; want %v", got, want)
}
}
// TestH2H2DNS tests that DNS resolution without external DNS with
// HTTP/2 backend works.
func TestH2H2DNS(t *testing.T) {
st := newServerTester([]string{"--http2-bridge", "--dns"}, t, noopHandler)
defer st.Close()
res, err := st.http2(requestParam{
name: "TestH2H2DNS",
})
if err != nil {
t.Fatalf("Error st.http2() = %v", err)
}
if got, want := res.status, 200; got != want {
t.Errorf("status = %v; want %v", got, want)
}
}
// TestH2APIBackendconfig exercise backendconfig API endpoint routine // TestH2APIBackendconfig exercise backendconfig API endpoint routine
// for successful case. // for successful case.
func TestH2APIBackendconfig(t *testing.T) { func TestH2APIBackendconfig(t *testing.T) {

View File

@ -101,10 +101,17 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
args := []string{} args := []string{}
backendTLS := false backendTLS := false
dns := false
externalDNS := false
for _, k := range src_args { for _, k := range src_args {
switch k { switch k {
case "--http2-bridge": case "--http2-bridge":
backendTLS = true backendTLS = true
case "--dns":
dns = true
case "--external-dns":
dns = true
externalDNS = true
default: default:
args = append(args, k) args = append(args, k)
} }
@ -117,7 +124,7 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
ts.TLS = new(tls.Config) ts.TLS = new(tls.Config)
ts.TLS.NextProtos = append(ts.TLS.NextProtos, "h2") ts.TLS.NextProtos = append(ts.TLS.NextProtos, "h2")
ts.StartTLS() ts.StartTLS()
args = append(args, "-k", "--backend-tls") args = append(args, "-k")
} else { } else {
ts.Start() ts.Start()
} }
@ -134,9 +141,23 @@ func newServerTesterInternal(src_args []string, t *testing.T, handler http.Handl
// URL.Host looks like "127.0.0.1:8080", but we want // URL.Host looks like "127.0.0.1:8080", but we want
// "127.0.0.1,8080" // "127.0.0.1,8080"
b := "-b" + strings.Replace(backendURL.Host, ":", ",", -1) b := "-b"
if !externalDNS {
b += fmt.Sprintf("%v;", strings.Replace(backendURL.Host, ":", ",", -1))
} else {
sep := strings.LastIndex(backendURL.Host, ":")
if sep == -1 {
t.Fatalf("backendURL.Host %v does not contain separator ':'", backendURL.Host)
}
// We use awesome service xip.io.
b += fmt.Sprintf("%v.xip.io,%v;", backendURL.Host[:sep], backendURL.Host[sep+1:])
}
if backendTLS { if backendTLS {
b += ";;proto=h2;tls" b += ";proto=h2;tls"
}
if dns {
b += ";dns"
} }
noTLS := "no-tls" noTLS := "no-tls"