| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal |
| 5 |
|
| 6 |
import ( |
| 7 |
"net/http" |
| 8 |
"net/http/httptest" |
| 9 |
"net/url" |
| 10 |
"strconv" |
| 11 |
"testing" |
| 12 |
|
| 13 |
"github.com/stretchr/testify/assert" |
| 14 |
"github.com/stretchr/testify/require" |
| 15 |
|
| 16 |
"go.opentelemetry.io/otel/attribute" |
| 17 |
"go.opentelemetry.io/otel/codes" |
| 18 |
) |
| 19 |
|
| 20 |
var hc = &HTTPConv{ |
| 21 |
NetConv: nc, |
| 22 |
|
| 23 |
EnduserIDKey: attribute.Key("enduser.id"), |
| 24 |
HTTPClientIPKey: attribute.Key("http.client_ip"), |
| 25 |
NetProtocolNameKey: attribute.Key("net.protocol.name"), |
| 26 |
NetProtocolVersionKey: attribute.Key("net.protocol.version"), |
| 27 |
HTTPMethodKey: attribute.Key("http.method"), |
| 28 |
HTTPRequestContentLengthKey: attribute.Key("http.request_content_length"), |
| 29 |
HTTPResponseContentLengthKey: attribute.Key("http.response_content_length"), |
| 30 |
HTTPRouteKey: attribute.Key("http.route"), |
| 31 |
HTTPSchemeHTTP: attribute.String("http.scheme", "http"), |
| 32 |
HTTPSchemeHTTPS: attribute.String("http.scheme", "https"), |
| 33 |
HTTPStatusCodeKey: attribute.Key("http.status_code"), |
| 34 |
HTTPTargetKey: attribute.Key("http.target"), |
| 35 |
HTTPURLKey: attribute.Key("http.url"), |
| 36 |
UserAgentOriginalKey: attribute.Key("user_agent.original"), |
| 37 |
} |
| 38 |
|
| 39 |
func TestHTTPClientResponse(t *testing.T) { |
| 40 |
const stat, n = 201, 397 |
| 41 |
resp := &http.Response{ |
| 42 |
StatusCode: stat, |
| 43 |
ContentLength: n, |
| 44 |
} |
| 45 |
got := hc.ClientResponse(resp) |
| 46 |
assert.Equal(t, 2, cap(got), "slice capacity") |
| 47 |
assert.ElementsMatch(t, []attribute.KeyValue{ |
| 48 |
attribute.Key("http.status_code").Int(stat), |
| 49 |
attribute.Key("http.response_content_length").Int(n), |
| 50 |
}, got) |
| 51 |
} |
| 52 |
|
| 53 |
func TestHTTPSClientRequest(t *testing.T) { |
| 54 |
req := &http.Request{ |
| 55 |
Method: http.MethodGet, |
| 56 |
URL: &url.URL{ |
| 57 |
Scheme: "https", |
| 58 |
Host: "127.0.0.1:443", |
| 59 |
Path: "/resource", |
| 60 |
}, |
| 61 |
Proto: "HTTP/1.0", |
| 62 |
ProtoMajor: 1, |
| 63 |
ProtoMinor: 0, |
| 64 |
} |
| 65 |
|
| 66 |
assert.Equal( |
| 67 |
t, |
| 68 |
[]attribute.KeyValue{ |
| 69 |
attribute.String("http.method", http.MethodGet), |
| 70 |
attribute.String("net.protocol.version", "1.0"), |
| 71 |
attribute.String("http.url", "https://127.0.0.1:443/resource"), |
| 72 |
attribute.String("net.peer.name", "127.0.0.1"), |
| 73 |
}, |
| 74 |
hc.ClientRequest(req), |
| 75 |
) |
| 76 |
} |
| 77 |
|
| 78 |
func TestHTTPClientRequest(t *testing.T) { |
| 79 |
const ( |
| 80 |
user = "alice" |
| 81 |
n = 128 |
| 82 |
agent = "Go-http-client/1.1" |
| 83 |
) |
| 84 |
req := &http.Request{ |
| 85 |
Method: http.MethodGet, |
| 86 |
URL: &url.URL{ |
| 87 |
Scheme: "http", |
| 88 |
Host: "127.0.0.1:8080", |
| 89 |
Path: "/resource", |
| 90 |
}, |
| 91 |
Proto: "HTTP/1.0", |
| 92 |
ProtoMajor: 1, |
| 93 |
ProtoMinor: 0, |
| 94 |
Header: http.Header{ |
| 95 |
"User-Agent": []string{agent}, |
| 96 |
}, |
| 97 |
ContentLength: n, |
| 98 |
} |
| 99 |
req.SetBasicAuth(user, "pswrd") |
| 100 |
|
| 101 |
assert.Equal( |
| 102 |
t, |
| 103 |
[]attribute.KeyValue{ |
| 104 |
attribute.String("http.method", http.MethodGet), |
| 105 |
attribute.String("net.protocol.version", "1.0"), |
| 106 |
attribute.String("http.url", "http://127.0.0.1:8080/resource"), |
| 107 |
attribute.String("net.peer.name", "127.0.0.1"), |
| 108 |
attribute.Int("net.peer.port", 8080), |
| 109 |
attribute.String("user_agent.original", agent), |
| 110 |
attribute.Int("http.request_content_length", n), |
| 111 |
attribute.String("enduser.id", user), |
| 112 |
}, |
| 113 |
hc.ClientRequest(req), |
| 114 |
) |
| 115 |
} |
| 116 |
|
| 117 |
func TestHTTPClientRequestRequired(t *testing.T) { |
| 118 |
req := new(http.Request) |
| 119 |
var got []attribute.KeyValue |
| 120 |
assert.NotPanics(t, func() { got = hc.ClientRequest(req) }) |
| 121 |
want := []attribute.KeyValue{ |
| 122 |
attribute.String("http.method", http.MethodGet), |
| 123 |
attribute.String("net.protocol.name", ""), |
| 124 |
attribute.String("http.url", ""), |
| 125 |
attribute.String("net.peer.name", ""), |
| 126 |
} |
| 127 |
assert.Equal(t, want, got) |
| 128 |
} |
| 129 |
|
| 130 |
func TestHTTPServerRequest(t *testing.T) { |
| 131 |
got := make(chan *http.Request, 1) |
| 132 |
handler := func(w http.ResponseWriter, r *http.Request) { |
| 133 |
got <- r |
| 134 |
w.WriteHeader(http.StatusOK) |
| 135 |
} |
| 136 |
|
| 137 |
srv := httptest.NewServer(http.HandlerFunc(handler)) |
| 138 |
defer srv.Close() |
| 139 |
|
| 140 |
srvURL, err := url.Parse(srv.URL) |
| 141 |
require.NoError(t, err) |
| 142 |
srvPort, err := strconv.ParseInt(srvURL.Port(), 10, 32) |
| 143 |
require.NoError(t, err) |
| 144 |
|
| 145 |
r, err := http.NewRequestWithContext(t.Context(), http.MethodGet, srv.URL, http.NoBody) |
| 146 |
require.NoError(t, err) |
| 147 |
|
| 148 |
resp, err := srv.Client().Do(r) |
| 149 |
require.NoError(t, err) |
| 150 |
require.NoError(t, resp.Body.Close()) |
| 151 |
|
| 152 |
req := <-got |
| 153 |
peer, peerPort := splitHostPort(req.RemoteAddr) |
| 154 |
|
| 155 |
const user = "alice" |
| 156 |
req.SetBasicAuth(user, "pswrd") |
| 157 |
|
| 158 |
const clientIP = "127.0.0.5" |
| 159 |
req.Header.Add("X-Forwarded-For", clientIP) |
| 160 |
|
| 161 |
assert.ElementsMatch(t, |
| 162 |
[]attribute.KeyValue{ |
| 163 |
attribute.String("http.method", http.MethodGet), |
| 164 |
attribute.String("http.scheme", "http"), |
| 165 |
attribute.String("net.protocol.version", "1.1"), |
| 166 |
attribute.String("net.host.name", srvURL.Hostname()), |
| 167 |
attribute.Int("net.host.port", int(srvPort)), |
| 168 |
attribute.String("net.sock.peer.addr", peer), |
| 169 |
attribute.Int("net.sock.peer.port", peerPort), |
| 170 |
attribute.String("user_agent.original", "Go-http-client/1.1"), |
| 171 |
attribute.String("enduser.id", user), |
| 172 |
attribute.String("http.client_ip", clientIP), |
| 173 |
}, |
| 174 |
hc.ServerRequest("", req)) |
| 175 |
} |
| 176 |
|
| 177 |
func TestHTTPServerName(t *testing.T) { |
| 178 |
req := new(http.Request) |
| 179 |
var got []attribute.KeyValue |
| 180 |
const ( |
| 181 |
host = "test.semconv.server" |
| 182 |
port = 8080 |
| 183 |
) |
| 184 |
portStr := strconv.Itoa(port) |
| 185 |
server := host + ":" + portStr |
| 186 |
assert.NotPanics(t, func() { got = hc.ServerRequest(server, req) }) |
| 187 |
assert.Contains(t, got, attribute.String("net.host.name", host)) |
| 188 |
assert.Contains(t, got, attribute.Int("net.host.port", port)) |
| 189 |
|
| 190 |
req = &http.Request{Host: "alt.host.name:" + portStr} |
| 191 |
// The server parameter does not include a port, ServerRequest should use |
| 192 |
// the port in the request Host field. |
| 193 |
assert.NotPanics(t, func() { got = hc.ServerRequest(host, req) }) |
| 194 |
assert.Contains(t, got, attribute.String("net.host.name", host)) |
| 195 |
assert.Contains(t, got, attribute.Int("net.host.port", port)) |
| 196 |
} |
| 197 |
|
| 198 |
func TestHTTPServerRequestFailsGracefully(t *testing.T) { |
| 199 |
req := new(http.Request) |
| 200 |
var got []attribute.KeyValue |
| 201 |
assert.NotPanics(t, func() { got = hc.ServerRequest("", req) }) |
| 202 |
want := []attribute.KeyValue{ |
| 203 |
attribute.String("http.method", http.MethodGet), |
| 204 |
attribute.String("http.scheme", "http"), |
| 205 |
attribute.String("net.protocol.name", ""), |
| 206 |
attribute.String("net.host.name", ""), |
| 207 |
} |
| 208 |
assert.ElementsMatch(t, want, got) |
| 209 |
} |
| 210 |
|
| 211 |
func TestMethod(t *testing.T) { |
| 212 |
assert.Equal(t, attribute.String("http.method", http.MethodPost), hc.method(http.MethodPost)) |
| 213 |
assert.Equal(t, attribute.String("http.method", http.MethodGet), hc.method("")) |
| 214 |
assert.Equal(t, attribute.String("http.method", "garbage"), hc.method("garbage")) |
| 215 |
} |
| 216 |
|
| 217 |
func TestScheme(t *testing.T) { |
| 218 |
assert.Equal(t, attribute.String("http.scheme", "http"), hc.scheme(false)) |
| 219 |
assert.Equal(t, attribute.String("http.scheme", "https"), hc.scheme(true)) |
| 220 |
} |
| 221 |
|
| 222 |
func TestProto(t *testing.T) { |
| 223 |
testCases := []struct { |
| 224 |
in string |
| 225 |
want attribute.KeyValue |
| 226 |
}{ |
| 227 |
{ |
| 228 |
in: "HTTP/1.0", |
| 229 |
want: attribute.String("net.protocol.version", "1.0"), |
| 230 |
}, |
| 231 |
{ |
| 232 |
in: "HTTP/1.1", |
| 233 |
want: attribute.String("net.protocol.version", "1.1"), |
| 234 |
}, |
| 235 |
{ |
| 236 |
in: "HTTP/2", |
| 237 |
want: attribute.String("net.protocol.version", "2.0"), |
| 238 |
}, |
| 239 |
{ |
| 240 |
in: "HTTP/3", |
| 241 |
want: attribute.String("net.protocol.version", "3.0"), |
| 242 |
}, |
| 243 |
{ |
| 244 |
in: "SPDY", |
| 245 |
want: attribute.String("net.protocol.name", "SPDY"), |
| 246 |
}, |
| 247 |
{ |
| 248 |
in: "QUIC", |
| 249 |
want: attribute.String("net.protocol.name", "QUIC"), |
| 250 |
}, |
| 251 |
{ |
| 252 |
in: "other", |
| 253 |
want: attribute.String("net.protocol.name", "other"), |
| 254 |
}, |
| 255 |
} |
| 256 |
for _, tc := range testCases { |
| 257 |
t.Run(tc.in, func(t *testing.T) { |
| 258 |
got := hc.proto(tc.in) |
| 259 |
assert.Equal(t, tc.want, got) |
| 260 |
}) |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
func TestServerClientIP(t *testing.T) { |
| 265 |
tests := []struct { |
| 266 |
xForwardedFor string |
| 267 |
want string |
| 268 |
}{ |
| 269 |
{"", ""}, |
| 270 |
{"127.0.0.1", "127.0.0.1"}, |
| 271 |
{"127.0.0.1,127.0.0.5", "127.0.0.1"}, |
| 272 |
} |
| 273 |
for _, test := range tests { |
| 274 |
got := serverClientIP(test.xForwardedFor) |
| 275 |
assert.Equal(t, test.want, got, test.xForwardedFor) |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
func TestRequiredHTTPPort(t *testing.T) { |
| 280 |
tests := []struct { |
| 281 |
https bool |
| 282 |
port int |
| 283 |
want int |
| 284 |
}{ |
| 285 |
{true, 443, -1}, |
| 286 |
{true, 80, 80}, |
| 287 |
{true, 8081, 8081}, |
| 288 |
{false, 443, 443}, |
| 289 |
{false, 80, -1}, |
| 290 |
{false, 8080, 8080}, |
| 291 |
} |
| 292 |
for _, test := range tests { |
| 293 |
got := requiredHTTPPort(test.https, test.port) |
| 294 |
assert.Equalf(t, test.want, got, "HTTP: %t, Port: %d", test.https, test.port) |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
func TestFirstHostPort(t *testing.T) { |
| 299 |
host, port := "127.0.0.1", 8080 |
| 300 |
hostport := "127.0.0.1:8080" |
| 301 |
sources := [][]string{ |
| 302 |
{hostport}, |
| 303 |
{"", hostport}, |
| 304 |
{"", "", hostport}, |
| 305 |
{"", "", hostport, ""}, |
| 306 |
{"", "", hostport, "127.0.0.3:80"}, |
| 307 |
} |
| 308 |
|
| 309 |
for _, src := range sources { |
| 310 |
h, p := firstHostPort(src...) |
| 311 |
assert.Equal(t, host, h, "%+v", src) |
| 312 |
assert.Equal(t, port, p, "%+v", src) |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
func TestRequestHeader(t *testing.T) { |
| 317 |
ips := []string{"127.0.0.5", "127.0.0.9"} |
| 318 |
user := []string{"alice"} |
| 319 |
h := http.Header{"ips": ips, "user": user} |
| 320 |
|
| 321 |
got := hc.RequestHeader(h) |
| 322 |
assert.Equal(t, 2, cap(got), "slice capacity") |
| 323 |
assert.ElementsMatch(t, []attribute.KeyValue{ |
| 324 |
attribute.StringSlice("http.request.header.ips", ips), |
| 325 |
attribute.StringSlice("http.request.header.user", user), |
| 326 |
}, got) |
| 327 |
} |
| 328 |
|
| 329 |
func TestResponseHeader(t *testing.T) { |
| 330 |
ips := []string{"127.0.0.5", "127.0.0.9"} |
| 331 |
user := []string{"alice"} |
| 332 |
h := http.Header{"ips": ips, "user": user} |
| 333 |
|
| 334 |
got := hc.ResponseHeader(h) |
| 335 |
assert.Equal(t, 2, cap(got), "slice capacity") |
| 336 |
assert.ElementsMatch(t, []attribute.KeyValue{ |
| 337 |
attribute.StringSlice("http.response.header.ips", ips), |
| 338 |
attribute.StringSlice("http.response.header.user", user), |
| 339 |
}, got) |
| 340 |
} |
| 341 |
|
| 342 |
func TestClientStatus(t *testing.T) { |
| 343 |
tests := []struct { |
| 344 |
code int |
| 345 |
stat codes.Code |
| 346 |
msg bool |
| 347 |
}{ |
| 348 |
{0, codes.Error, true}, |
| 349 |
{http.StatusContinue, codes.Unset, false}, |
| 350 |
{http.StatusSwitchingProtocols, codes.Unset, false}, |
| 351 |
{http.StatusProcessing, codes.Unset, false}, |
| 352 |
{http.StatusEarlyHints, codes.Unset, false}, |
| 353 |
{http.StatusOK, codes.Unset, false}, |
| 354 |
{http.StatusCreated, codes.Unset, false}, |
| 355 |
{http.StatusAccepted, codes.Unset, false}, |
| 356 |
{http.StatusNonAuthoritativeInfo, codes.Unset, false}, |
| 357 |
{http.StatusNoContent, codes.Unset, false}, |
| 358 |
{http.StatusResetContent, codes.Unset, false}, |
| 359 |
{http.StatusPartialContent, codes.Unset, false}, |
| 360 |
{http.StatusMultiStatus, codes.Unset, false}, |
| 361 |
{http.StatusAlreadyReported, codes.Unset, false}, |
| 362 |
{http.StatusIMUsed, codes.Unset, false}, |
| 363 |
{http.StatusMultipleChoices, codes.Unset, false}, |
| 364 |
{http.StatusMovedPermanently, codes.Unset, false}, |
| 365 |
{http.StatusFound, codes.Unset, false}, |
| 366 |
{http.StatusSeeOther, codes.Unset, false}, |
| 367 |
{http.StatusNotModified, codes.Unset, false}, |
| 368 |
{http.StatusUseProxy, codes.Unset, false}, |
| 369 |
{306, codes.Error, true}, |
| 370 |
{http.StatusTemporaryRedirect, codes.Unset, false}, |
| 371 |
{http.StatusPermanentRedirect, codes.Unset, false}, |
| 372 |
{http.StatusBadRequest, codes.Error, false}, |
| 373 |
{http.StatusUnauthorized, codes.Error, false}, |
| 374 |
{http.StatusPaymentRequired, codes.Error, false}, |
| 375 |
{http.StatusForbidden, codes.Error, false}, |
| 376 |
{http.StatusNotFound, codes.Error, false}, |
| 377 |
{http.StatusMethodNotAllowed, codes.Error, false}, |
| 378 |
{http.StatusNotAcceptable, codes.Error, false}, |
| 379 |
{http.StatusProxyAuthRequired, codes.Error, false}, |
| 380 |
{http.StatusRequestTimeout, codes.Error, false}, |
| 381 |
{http.StatusConflict, codes.Error, false}, |
| 382 |
{http.StatusGone, codes.Error, false}, |
| 383 |
{http.StatusLengthRequired, codes.Error, false}, |
| 384 |
{http.StatusPreconditionFailed, codes.Error, false}, |
| 385 |
{http.StatusRequestEntityTooLarge, codes.Error, false}, |
| 386 |
{http.StatusRequestURITooLong, codes.Error, false}, |
| 387 |
{http.StatusUnsupportedMediaType, codes.Error, false}, |
| 388 |
{http.StatusRequestedRangeNotSatisfiable, codes.Error, false}, |
| 389 |
{http.StatusExpectationFailed, codes.Error, false}, |
| 390 |
{http.StatusTeapot, codes.Error, false}, |
| 391 |
{http.StatusMisdirectedRequest, codes.Error, false}, |
| 392 |
{http.StatusUnprocessableEntity, codes.Error, false}, |
| 393 |
{http.StatusLocked, codes.Error, false}, |
| 394 |
{http.StatusFailedDependency, codes.Error, false}, |
| 395 |
{http.StatusTooEarly, codes.Error, false}, |
| 396 |
{http.StatusUpgradeRequired, codes.Error, false}, |
| 397 |
{http.StatusPreconditionRequired, codes.Error, false}, |
| 398 |
{http.StatusTooManyRequests, codes.Error, false}, |
| 399 |
{http.StatusRequestHeaderFieldsTooLarge, codes.Error, false}, |
| 400 |
{http.StatusUnavailableForLegalReasons, codes.Error, false}, |
| 401 |
{http.StatusInternalServerError, codes.Error, false}, |
| 402 |
{http.StatusNotImplemented, codes.Error, false}, |
| 403 |
{http.StatusBadGateway, codes.Error, false}, |
| 404 |
{http.StatusServiceUnavailable, codes.Error, false}, |
| 405 |
{http.StatusGatewayTimeout, codes.Error, false}, |
| 406 |
{http.StatusHTTPVersionNotSupported, codes.Error, false}, |
| 407 |
{http.StatusVariantAlsoNegotiates, codes.Error, false}, |
| 408 |
{http.StatusInsufficientStorage, codes.Error, false}, |
| 409 |
{http.StatusLoopDetected, codes.Error, false}, |
| 410 |
{http.StatusNotExtended, codes.Error, false}, |
| 411 |
{http.StatusNetworkAuthenticationRequired, codes.Error, false}, |
| 412 |
{600, codes.Error, true}, |
| 413 |
} |
| 414 |
|
| 415 |
for _, test := range tests { |
| 416 |
c, msg := hc.ClientStatus(test.code) |
| 417 |
assert.Equal(t, test.stat, c) |
| 418 |
if test.msg && msg == "" { |
| 419 |
t.Errorf("expected non-empty message for %d", test.code) |
| 420 |
} else if !test.msg && msg != "" { |
| 421 |
t.Errorf("expected empty message for %d, got: %s", test.code, msg) |
| 422 |
} |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
func TestServerStatus(t *testing.T) { |
| 427 |
tests := []struct { |
| 428 |
code int |
| 429 |
stat codes.Code |
| 430 |
msg bool |
| 431 |
}{ |
| 432 |
{0, codes.Error, true}, |
| 433 |
{http.StatusContinue, codes.Unset, false}, |
| 434 |
{http.StatusSwitchingProtocols, codes.Unset, false}, |
| 435 |
{http.StatusProcessing, codes.Unset, false}, |
| 436 |
{http.StatusEarlyHints, codes.Unset, false}, |
| 437 |
{http.StatusOK, codes.Unset, false}, |
| 438 |
{http.StatusCreated, codes.Unset, false}, |
| 439 |
{http.StatusAccepted, codes.Unset, false}, |
| 440 |
{http.StatusNonAuthoritativeInfo, codes.Unset, false}, |
| 441 |
{http.StatusNoContent, codes.Unset, false}, |
| 442 |
{http.StatusResetContent, codes.Unset, false}, |
| 443 |
{http.StatusPartialContent, codes.Unset, false}, |
| 444 |
{http.StatusMultiStatus, codes.Unset, false}, |
| 445 |
{http.StatusAlreadyReported, codes.Unset, false}, |
| 446 |
{http.StatusIMUsed, codes.Unset, false}, |
| 447 |
{http.StatusMultipleChoices, codes.Unset, false}, |
| 448 |
{http.StatusMovedPermanently, codes.Unset, false}, |
| 449 |
{http.StatusFound, codes.Unset, false}, |
| 450 |
{http.StatusSeeOther, codes.Unset, false}, |
| 451 |
{http.StatusNotModified, codes.Unset, false}, |
| 452 |
{http.StatusUseProxy, codes.Unset, false}, |
| 453 |
{306, codes.Error, true}, |
| 454 |
{http.StatusTemporaryRedirect, codes.Unset, false}, |
| 455 |
{http.StatusPermanentRedirect, codes.Unset, false}, |
| 456 |
{http.StatusBadRequest, codes.Unset, false}, |
| 457 |
{http.StatusUnauthorized, codes.Unset, false}, |
| 458 |
{http.StatusPaymentRequired, codes.Unset, false}, |
| 459 |
{http.StatusForbidden, codes.Unset, false}, |
| 460 |
{http.StatusNotFound, codes.Unset, false}, |
| 461 |
{http.StatusMethodNotAllowed, codes.Unset, false}, |
| 462 |
{http.StatusNotAcceptable, codes.Unset, false}, |
| 463 |
{http.StatusProxyAuthRequired, codes.Unset, false}, |
| 464 |
{http.StatusRequestTimeout, codes.Unset, false}, |
| 465 |
{http.StatusConflict, codes.Unset, false}, |
| 466 |
{http.StatusGone, codes.Unset, false}, |
| 467 |
{http.StatusLengthRequired, codes.Unset, false}, |
| 468 |
{http.StatusPreconditionFailed, codes.Unset, false}, |
| 469 |
{http.StatusRequestEntityTooLarge, codes.Unset, false}, |
| 470 |
{http.StatusRequestURITooLong, codes.Unset, false}, |
| 471 |
{http.StatusUnsupportedMediaType, codes.Unset, false}, |
| 472 |
{http.StatusRequestedRangeNotSatisfiable, codes.Unset, false}, |
| 473 |
{http.StatusExpectationFailed, codes.Unset, false}, |
| 474 |
{http.StatusTeapot, codes.Unset, false}, |
| 475 |
{http.StatusMisdirectedRequest, codes.Unset, false}, |
| 476 |
{http.StatusUnprocessableEntity, codes.Unset, false}, |
| 477 |
{http.StatusLocked, codes.Unset, false}, |
| 478 |
{http.StatusFailedDependency, codes.Unset, false}, |
| 479 |
{http.StatusTooEarly, codes.Unset, false}, |
| 480 |
{http.StatusUpgradeRequired, codes.Unset, false}, |
| 481 |
{http.StatusPreconditionRequired, codes.Unset, false}, |
| 482 |
{http.StatusTooManyRequests, codes.Unset, false}, |
| 483 |
{http.StatusRequestHeaderFieldsTooLarge, codes.Unset, false}, |
| 484 |
{http.StatusUnavailableForLegalReasons, codes.Unset, false}, |
| 485 |
{http.StatusInternalServerError, codes.Error, false}, |
| 486 |
{http.StatusNotImplemented, codes.Error, false}, |
| 487 |
{http.StatusBadGateway, codes.Error, false}, |
| 488 |
{http.StatusServiceUnavailable, codes.Error, false}, |
| 489 |
{http.StatusGatewayTimeout, codes.Error, false}, |
| 490 |
{http.StatusHTTPVersionNotSupported, codes.Error, false}, |
| 491 |
{http.StatusVariantAlsoNegotiates, codes.Error, false}, |
| 492 |
{http.StatusInsufficientStorage, codes.Error, false}, |
| 493 |
{http.StatusLoopDetected, codes.Error, false}, |
| 494 |
{http.StatusNotExtended, codes.Error, false}, |
| 495 |
{http.StatusNetworkAuthenticationRequired, codes.Error, false}, |
| 496 |
{600, codes.Error, true}, |
| 497 |
} |
| 498 |
|
| 499 |
for _, test := range tests { |
| 500 |
c, msg := hc.ServerStatus(test.code) |
| 501 |
assert.Equal(t, test.stat, c) |
| 502 |
if test.msg && msg == "" { |
| 503 |
t.Errorf("expected non-empty message for %d", test.code) |
| 504 |
} else if !test.msg && msg != "" { |
| 505 |
t.Errorf("expected empty message for %d, got: %s", test.code, msg) |
| 506 |
} |
| 507 |
} |
| 508 |
} |