Files
telemetry/config/confighttp/clientinfohandler_test.go
Alex BotenandGitHub 1d2c21dbe3 [chore] small test improvements (#11211)
Clean up some inconsistencies in the test code across the components.

Signed-off-by: Alex Boten <[email protected]>
2024-09-18 13:47:25 -07:00

53 lines
959 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package confighttp // import "go.opentelemetry.io/collector/config/confighttp"
import (
"net"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
var _ http.Handler = (*clientInfoHandler)(nil)
func TestParseIP(t *testing.T) {
testCases := []struct {
name string
input string
expected *net.IPAddr
}{
{
name: "addr",
input: "1.2.3.4",
expected: &net.IPAddr{
IP: net.IPv4(1, 2, 3, 4),
},
},
{
name: "addr:port",
input: "1.2.3.4:33455",
expected: &net.IPAddr{
IP: net.IPv4(1, 2, 3, 4),
},
},
{
name: "protocol://addr:port",
input: "http://1.2.3.4:33455",
expected: nil,
},
{
name: "addr/path",
input: "1.2.3.4/orders",
expected: nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, parseIP(tt.input))
})
}
}