Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/mimir/rules/kubernetes/rules_test.go
4096 views
1
package rules
2
3
import (
4
"testing"
5
6
"github.com/grafana/agent/pkg/river"
7
"github.com/stretchr/testify/require"
8
"k8s.io/client-go/util/workqueue"
9
)
10
11
func TestEventTypeIsHashable(t *testing.T) {
12
// This test is here to ensure that the EventType type is hashable according to the workqueue implementation
13
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter())
14
queue.AddRateLimited(event{})
15
}
16
17
func TestRiverConfig(t *testing.T) {
18
var exampleRiverConfig = `
19
address = "GRAFANA_CLOUD_METRICS_URL"
20
basic_auth {
21
username = "GRAFANA_CLOUD_USER"
22
password = "GRAFANA_CLOUD_API_KEY"
23
}
24
`
25
26
var args Arguments
27
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
28
require.NoError(t, err)
29
}
30
31
func TestBadRiverConfig(t *testing.T) {
32
var exampleRiverConfig = `
33
address = "GRAFANA_CLOUD_METRICS_URL"
34
bearer_token = "token"
35
bearer_token_file = "/path/to/file.token"
36
`
37
38
// Make sure the squashed HTTPClientConfig Validate function is being utilized correctly
39
var args Arguments
40
err := river.Unmarshal([]byte(exampleRiverConfig), &args)
41
require.ErrorContains(t, err, "at most one of bearer_token & bearer_token_file must be configured")
42
}
43
44