Files
5e5860c524 Support npipe transport in confignet (#14985)
#### Description

Support using Windows named pipes as a transport in confignet. The
implementation uses https://github.com/microsoft/go-winio/.

#### Link to tracking issue
Fixes
https://github.com/open-telemetry/opentelemetry-collector/issues/15085

#### Testing

Added unit tests covering the new transport. There's also a unit test
for validating named path paths.

#### Documentation

Added the new value to the config schema and README.

---------

Co-authored-by: Alex Boten <[email protected]>
2026-04-27 16:16:18 +00:00

55 lines
1.1 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build windows
package confignet
import (
"context"
"net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNpipeListenAndDial(t *testing.T) {
endpoint := `\\.\pipe\otel-test-confignet`
nas := &AddrConfig{
Endpoint: endpoint,
Transport: TransportTypeNpipe,
}
ln, err := nas.Listen(context.Background())
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, ln.Close())
})
defer ln.Close()
done := make(chan bool, 1)
go func() {
conn, errGo := ln.Accept()
assert.NoError(t, errGo)
buf := make([]byte, 10)
var numChr int
numChr, errGo = conn.Read(buf)
assert.NoError(t, errGo)
assert.Equal(t, "test", string(buf[:numChr]))
assert.NoError(t, conn.Close())
done <- true
}()
nac := &AddrConfig{
Endpoint: endpoint,
Transport: TransportTypeNpipe,
}
var conn net.Conn
conn, err = nac.Dial(context.Background())
require.NoError(t, err)
_, err = conn.Write([]byte("test"))
assert.NoError(t, err)
assert.NoError(t, conn.Close())
<-done
}