Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/otelcol/receiver/jaeger/jaeger_test.go
4096 views
1
package jaeger_test
2
3
import (
4
"fmt"
5
"testing"
6
"time"
7
8
"github.com/grafana/agent/component/otelcol/receiver/jaeger"
9
"github.com/grafana/agent/pkg/flow/componenttest"
10
"github.com/grafana/agent/pkg/river"
11
"github.com/grafana/agent/pkg/util"
12
"github.com/phayes/freeport"
13
"github.com/stretchr/testify/require"
14
)
15
16
// Test ensures that otelcol.receiver.jaeger can start successfully.
17
func Test(t *testing.T) {
18
httpAddr := getFreeAddr(t)
19
20
ctx := componenttest.TestContext(t)
21
l := util.TestLogger(t)
22
23
ctrl, err := componenttest.NewControllerFromID(l, "otelcol.receiver.jaeger")
24
require.NoError(t, err)
25
26
cfg := fmt.Sprintf(`
27
protocols {
28
grpc {
29
endpoint = "%s"
30
}
31
}
32
33
output { /* no-op */ }
34
`, httpAddr)
35
var args jaeger.Arguments
36
require.NoError(t, river.Unmarshal([]byte(cfg), &args))
37
38
go func() {
39
err := ctrl.Run(ctx, args)
40
require.NoError(t, err)
41
}()
42
43
require.NoError(t, ctrl.WaitRunning(time.Second))
44
45
// TODO(rfratto): is it worthwhile trying to make sure we can send data over
46
// the client or can we trust that getting the component to run successfully
47
// is enough?
48
time.Sleep(100 * time.Millisecond)
49
}
50
51
func TestArguments_UnmarshalRiver(t *testing.T) {
52
t.Run("grpc", func(t *testing.T) {
53
in := `
54
protocols { grpc {} }
55
output {}
56
`
57
58
var args jaeger.Arguments
59
require.NoError(t, river.Unmarshal([]byte(in), &args))
60
61
require.Equal(t, jaeger.DefaultArguments.Protocols.GRPC, args.Protocols.GRPC)
62
require.Nil(t, args.Protocols.ThriftHTTP)
63
require.Nil(t, args.Protocols.ThriftBinary)
64
require.Nil(t, args.Protocols.ThriftCompact)
65
})
66
67
t.Run("thrift_http", func(t *testing.T) {
68
in := `
69
protocols { thrift_http {} }
70
output {}
71
`
72
73
var args jaeger.Arguments
74
require.NoError(t, river.Unmarshal([]byte(in), &args))
75
76
require.Nil(t, args.Protocols.GRPC)
77
require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftHTTP, args.Protocols.ThriftHTTP)
78
require.Nil(t, args.Protocols.ThriftBinary)
79
require.Nil(t, args.Protocols.ThriftCompact)
80
})
81
82
t.Run("thrift_binary", func(t *testing.T) {
83
in := `
84
protocols { thrift_binary {} }
85
output {}
86
`
87
88
var args jaeger.Arguments
89
require.NoError(t, river.Unmarshal([]byte(in), &args))
90
91
require.Nil(t, args.Protocols.GRPC)
92
require.Nil(t, args.Protocols.ThriftHTTP)
93
require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftBinary, args.Protocols.ThriftBinary)
94
require.Nil(t, args.Protocols.ThriftCompact)
95
})
96
97
t.Run("thrift_compact", func(t *testing.T) {
98
in := `
99
protocols { thrift_compact {} }
100
output {}
101
`
102
103
var args jaeger.Arguments
104
require.NoError(t, river.Unmarshal([]byte(in), &args))
105
106
require.Nil(t, args.Protocols.GRPC)
107
require.Nil(t, args.Protocols.ThriftHTTP)
108
require.Nil(t, args.Protocols.ThriftBinary)
109
require.Equal(t, jaeger.DefaultArguments.Protocols.ThriftCompact, args.Protocols.ThriftCompact)
110
})
111
}
112
113
func getFreeAddr(t *testing.T) string {
114
t.Helper()
115
116
portNumber, err := freeport.GetFreePort()
117
require.NoError(t, err)
118
119
return fmt.Sprintf("localhost:%d", portNumber)
120
}
121
122