Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/loki/source/kafka/kafka_test.go
4096 views
1
package kafka
2
3
import (
4
"testing"
5
6
"github.com/grafana/agent/pkg/river"
7
"github.com/stretchr/testify/require"
8
)
9
10
func TestRiverConfig(t *testing.T) {
11
var exampleRiverConfig = `
12
brokers = ["localhost:9092","localhost:23456"]
13
topics = ["quickstart-events"]
14
labels = {component = "loki.source.kafka"}
15
forward_to = []
16
use_incoming_timestamp = true
17
`
18
19
var args Arguments
20
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
21
require.NoError(t, err)
22
}
23
24
func TestTLSRiverConfig(t *testing.T) {
25
var exampleRiverConfig = `
26
brokers = ["localhost:9092","localhost:23456"]
27
topics = ["quickstart-events"]
28
authentication {
29
type = "ssl"
30
tls_config {
31
cert_file = "/fake/file.cert"
32
key_file = "/fake/file.key"
33
}
34
}
35
labels = {component = "loki.source.kafka"}
36
forward_to = []
37
`
38
39
var args Arguments
40
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
41
require.NoError(t, err)
42
}
43
44
func TestSASLRiverConfig(t *testing.T) {
45
var exampleRiverConfig = `
46
brokers = ["localhost:9092","localhost:23456"]
47
topics = ["quickstart-events"]
48
authentication {
49
type = "sasl"
50
sasl_config {
51
user = "user"
52
password = "password"
53
}
54
}
55
labels = {component = "loki.source.kafka"}
56
forward_to = []
57
`
58
59
var args Arguments
60
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
61
require.NoError(t, err)
62
}
63
64
func TestSASLOAuthRiverConfig(t *testing.T) {
65
var exampleRiverConfig = `
66
brokers = ["localhost:9092", "localhost:23456"]
67
topics = ["quickstart-events"]
68
69
authentication {
70
type = "sasl"
71
sasl_config {
72
mechanism = "OAUTHBEARER"
73
oauth_config {
74
token_provider = "azure"
75
scopes = ["my-scope"]
76
}
77
}
78
}
79
labels = {component = "loki.source.kafka"}
80
forward_to = []
81
`
82
83
var args Arguments
84
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
85
require.NoError(t, err)
86
}
87
88