Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/discovery/consul/consul_test.go
4096 views
1
package consul
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
server = "consul.example.com:8500"
13
services = ["my-service"]
14
token = "my-token"
15
allow_stale = false
16
node_meta = { foo = "bar" }
17
`
18
19
var args Arguments
20
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
21
require.NoError(t, err)
22
}
23
24
func TestBadRiverConfig(t *testing.T) {
25
var exampleRiverConfig = `
26
server = "consul.example.com:8500"
27
services = ["my-service"]
28
bearer_token = "token"
29
bearer_token_file = "/path/to/file.token"
30
`
31
32
// Make sure the squashed HTTPClientConfig Validate function is being utilized correctly
33
var args Arguments
34
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
35
require.ErrorContains(t, err, "at most one of bearer_token & bearer_token_file must be configured")
36
}
37
38