Browse Source

Start of integration tests with curl

Brad Fitzpatrick 11 years ago
parent
commit
5061e99073
2 changed files with 51 additions and 1 deletions
  1. 3 1
      http2.go
  2. 48 0
      http2_test.go

+ 3 - 1
http2.go

@@ -1,4 +1,6 @@
-// Copyright 2014 The Go Authors.
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
 // See https://code.google.com/p/go/source/browse/CONTRIBUTORS
 // Licensed under the same terms as Go itself:
 // https://code.google.com/p/go/source/browse/LICENSE

+ 48 - 0
http2_test.go

@@ -0,0 +1,48 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// See https://code.google.com/p/go/source/browse/CONTRIBUTORS
+// Licensed under the same terms as Go itself:
+// https://code.google.com/p/go/source/browse/LICENSE
+
+package http2
+
+import (
+	"io"
+	"net/http"
+	"net/http/httptest"
+	"os/exec"
+	"strings"
+	"testing"
+)
+
+func TestServer(t *testing.T) {
+	requireCurl(t)
+
+	ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		io.WriteString(w, "Hello, test.")
+	}))
+	ConfigureServer(ts.Config, &Server{})
+	ts.StartTLS()
+	defer ts.Close()
+	out, err := curl(t, "--http2", "--insecure", "-v", ts.URL).CombinedOutput()
+	if err != nil {
+		t.Fatalf("Error fetching with curl: %v, %s", err, out)
+	}
+	t.Logf("Got: %s", out)
+}
+
+// Verify that curl has http2.
+func requireCurl(t *testing.T) {
+	out, err := curl(t, "--version").CombinedOutput()
+	if err != nil {
+		t.Skipf("failed to determine curl features; skipping test")
+	}
+	if !strings.Contains(string(out), "HTTP2") {
+		t.Skip("curl doesn't support HTTP2; skipping test")
+	}
+}
+
+func curl(t *testing.T, args ...string) *exec.Cmd {
+	return exec.Command("docker", append([]string{"run", "--net=host", "gohttp2/curl"}, args...)...)
+}