| 1 |
// Code generated by gotmpl. DO NOT MODIFY. |
| 2 |
// source: internal/shared/semconv/util_test.go.tmpl |
| 3 |
|
| 4 |
// Copyright The OpenTelemetry Authors |
| 5 |
// SPDX-License-Identifier: Apache-2.0 |
| 6 |
|
| 7 |
package semconv |
| 8 |
|
| 9 |
import ( |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/stretchr/testify/assert" |
| 13 |
) |
| 14 |
|
| 15 |
func TestSplitHostPort(t *testing.T) { |
| 16 |
tests := []struct { |
| 17 |
hostport string |
| 18 |
host string |
| 19 |
port int |
| 20 |
}{ |
| 21 |
{"", "", -1}, |
| 22 |
{":8080", "", 8080}, |
| 23 |
{"127.0.0.1", "127.0.0.1", -1}, |
| 24 |
{"www.example.com", "www.example.com", -1}, |
| 25 |
{"127.0.0.1%25en0", "127.0.0.1%25en0", -1}, |
| 26 |
{"[]", "", -1}, // Ensure this doesn't panic. |
| 27 |
{"[fe80::1", "", -1}, |
| 28 |
{"[fe80::1]", "fe80::1", -1}, |
| 29 |
{"[fe80::1%25en0]", "fe80::1%25en0", -1}, |
| 30 |
{"[fe80::1]:8080", "fe80::1", 8080}, |
| 31 |
{"[fe80::1]::", "", -1}, // Too many colons. |
| 32 |
{"127.0.0.1:", "127.0.0.1", -1}, |
| 33 |
{"127.0.0.1:port", "127.0.0.1", -1}, |
| 34 |
{"127.0.0.1:8080", "127.0.0.1", 8080}, |
| 35 |
{"www.example.com:8080", "www.example.com", 8080}, |
| 36 |
{"127.0.0.1%25en0:8080", "127.0.0.1%25en0", 8080}, |
| 37 |
} |
| 38 |
|
| 39 |
for _, test := range tests { |
| 40 |
h, p := SplitHostPort(test.hostport) |
| 41 |
assert.Equal(t, test.host, h, test.hostport) |
| 42 |
assert.Equal(t, test.port, p, test.hostport) |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func TestStandardizeHTTPMethod(t *testing.T) { |
| 47 |
tests := []struct { |
| 48 |
method string |
| 49 |
want string |
| 50 |
}{ |
| 51 |
{"GET", "GET"}, |
| 52 |
{"get", "GET"}, |
| 53 |
{"POST", "POST"}, |
| 54 |
{"post", "POST"}, |
| 55 |
{"PUT", "PUT"}, |
| 56 |
{"put", "PUT"}, |
| 57 |
{"DELETE", "DELETE"}, |
| 58 |
{"delete", "DELETE"}, |
| 59 |
{"HEAD", "HEAD"}, |
| 60 |
{"head", "HEAD"}, |
| 61 |
{"OPTIONS", "OPTIONS"}, |
| 62 |
{"options", "OPTIONS"}, |
| 63 |
{"CONNECT", "CONNECT"}, |
| 64 |
{"connect", "CONNECT"}, |
| 65 |
{"TRACE", "TRACE"}, |
| 66 |
{"trace", "TRACE"}, |
| 67 |
{"PATCH", "PATCH"}, |
| 68 |
{"patch", "PATCH"}, |
| 69 |
{"unknown", "_OTHER"}, |
| 70 |
{"", "_OTHER"}, |
| 71 |
} |
| 72 |
for _, test := range tests { |
| 73 |
assert.Equal(t, test.want, standardizeHTTPMethod(test.method)) |
| 74 |
} |
| 75 |
} |