mirror of https://github.com/helm/helm
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
933 B
50 lines
933 B
package dm
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDebugTransport(t *testing.T) {
|
|
handler := func(w http.ResponseWriter, req *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write([]byte(`{"status":"awesome"}`))
|
|
}
|
|
|
|
server := httptest.NewServer(http.HandlerFunc(handler))
|
|
defer server.Close()
|
|
|
|
var output bytes.Buffer
|
|
|
|
client := &http.Client{
|
|
Transport: debugTransport{
|
|
Writer: &output,
|
|
},
|
|
}
|
|
|
|
_, err := client.Get(server.URL)
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
expected := []string{
|
|
"GET / HTTP/1.1",
|
|
"Accept-Encoding: gzip",
|
|
"HTTP/1.1 200 OK",
|
|
"Content-Length: 20",
|
|
"Content-Type: application/json",
|
|
`{"status":"awesome"}`,
|
|
}
|
|
actual := output.String()
|
|
|
|
for _, match := range expected {
|
|
if !strings.Contains(actual, match) {
|
|
t.Errorf("Expected %s to contain %s", actual, match)
|
|
}
|
|
}
|
|
}
|