MCPcopy Create free account
hub / github.com/olivere/elastic / TestResponseErrorHTML

Function TestResponseErrorHTML

errors_test.go:100–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

98}
99
100func TestResponseErrorHTML(t *testing.T) {
101 raw := "HTTP/1.1 413 Request Entity Too Large\r\n" +
102 "\r\n" +
103 `<html>
104<head><title>413 Request Entity Too Large</title></head>
105<body bgcolor="white">
106<center><h1>413 Request Entity Too Large</h1></center>
107<hr><center>nginx/1.6.2</center>
108</body>
109</html>` + "\r\n"
110 r := bufio.NewReader(strings.NewReader(raw))
111
112 req, err := http.NewRequest("GET", "/", nil)
113 if err != nil {
114 t.Fatal(err)
115 }
116
117 resp, err := http.ReadResponse(r, nil)
118 if err != nil {
119 t.Fatal(err)
120 }
121 err = checkResponse(req, resp)
122 if err == nil {
123 t.Fatalf("expected error; got: %v", err)
124 }
125
126 // Check for correct error message
127 expected := fmt.Sprintf("elastic: Error %d (%s)", http.StatusRequestEntityTooLarge, http.StatusText(http.StatusRequestEntityTooLarge))
128 got := err.Error()
129 if got != expected {
130 t.Fatalf("expected %q; got: %q", expected, got)
131 }
132}
133
134func TestResponseErrorWithIgnore(t *testing.T) {
135 raw := "HTTP/1.1 404 Not Found\r\n" +

Callers

nothing calls this directly

Calls 4

checkResponseFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…