Path: blob/main/component/otelcol/receiver/jaeger/jaeger_test.go
4096 views
package jaeger_test12import (3"fmt"4"testing"5"time"67"github.com/grafana/agent/component/otelcol/receiver/jaeger"8"github.com/grafana/agent/pkg/flow/componenttest"9"github.com/grafana/agent/pkg/river"10"github.com/grafana/agent/pkg/util"11"github.com/phayes/freeport"12"github.com/stretchr/testify/require"13)1415// Test ensures that otelcol.receiver.jaeger can start successfully.16func Test(t *testing.T) {17httpAddr := getFreeAddr(t)1819ctx := componenttest.TestContext(t)20l := util.TestLogger(t)2122ctrl, err := componenttest.NewControllerFromID(l, "otelcol.receiver.jaeger")23require.NoError(t, err)2425cfg := fmt.Sprintf(`26protocols {27grpc {28endpoint = "%s"29}30}3132output { /* no-op */ }33`, httpAddr)34var args jaeger.Arguments35require.NoError(t, river.Unmarshal([]byte(cfg), &args))3637go func() {38err := ctrl.Run(ctx, args)39require.NoError(t, err)40}()4142require.NoError(t, ctrl.WaitRunning(time.Second))4344// TODO(rfratto): is it worthwhile trying to make sure we can send data over45// the client or can we trust that getting the component to run successfully46// is enough?47time.Sleep(100 * time.Millisecond)48}4950func TestArguments_UnmarshalRiver(t *testing.T) {51t.Run("grpc", func(t *testing.T) {52in := `53protocols { grpc {} }54output {}55`5657var args jaeger.Arguments58require.NoError(t, river.Unmarshal([]byte(in), &args))5960require.Equal(t, jaeger.DefaultArguments.Protocols.GRPC, args.Protocols.GRPC)61require.Nil(t, args.Protocols.ThriftHTTP)62require.Nil(t, args.Protocols.ThriftBinary)63require.Nil(t, args.Protocols.ThriftCompact)64})6566t.Run("thrift_http", func(t *testing.T) {67in := `68protocols { thrift_http {} }69output {}70`7172var args jaeger.Arguments73require.NoError(t, river.Unmarshal([]byte(in), &args))7475require.Nil(t, args.Protocols.GRPC)76require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftHTTP, args.Protocols.ThriftHTTP)77require.Nil(t, args.Protocols.ThriftBinary)78require.Nil(t, args.Protocols.ThriftCompact)79})8081t.Run("thrift_binary", func(t *testing.T) {82in := `83protocols { thrift_binary {} }84output {}85`8687var args jaeger.Arguments88require.NoError(t, river.Unmarshal([]byte(in), &args))8990require.Nil(t, args.Protocols.GRPC)91require.Nil(t, args.Protocols.ThriftHTTP)92require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftBinary, args.Protocols.ThriftBinary)93require.Nil(t, args.Protocols.ThriftCompact)94})9596t.Run("thrift_compact", func(t *testing.T) {97in := `98protocols { thrift_compact {} }99output {}100`101102var args jaeger.Arguments103require.NoError(t, river.Unmarshal([]byte(in), &args))104105require.Nil(t, args.Protocols.GRPC)106require.Nil(t, args.Protocols.ThriftHTTP)107require.Nil(t, args.Protocols.ThriftBinary)108require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftCompact, args.Protocols.ThriftCompact)109})110}111112func getFreeAddr(t *testing.T) string {113t.Helper()114115portNumber, err := freeport.GetFreePort()116require.NoError(t, err)117118return fmt.Sprintf("localhost:%d", portNumber)119}120121122