Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/instance/configstore/codec_test.go
5327 views
1
package configstore
2
3
import (
4
"testing"
5
6
"github.com/stretchr/testify/require"
7
)
8
9
func TestCodec(t *testing.T) {
10
exampleConfig := `name: 'test'
11
host_filter: false
12
scrape_configs:
13
- job_name: process-1
14
static_configs:
15
- targets: ['process-1:80']
16
labels:
17
cluster: 'local'
18
origin: 'agent'`
19
20
c := &yamlCodec{}
21
bb, err := c.Encode(exampleConfig)
22
require.NoError(t, err)
23
24
out, err := c.Decode(bb)
25
require.NoError(t, err)
26
require.Equal(t, exampleConfig, out)
27
}
28
29
// TestCodec_Decode_Nil makes sure that if Decode is called with an empty value,
30
// which may happen when a key is deleted, that no error occurs and instead a
31
// nil value is returned.
32
func TestCodec_Decode_Nil(t *testing.T) {
33
c := &yamlCodec{}
34
35
input := [][]byte{nil, make([]byte, 0)}
36
for _, bb := range input {
37
out, err := c.Decode(bb)
38
require.Nil(t, err)
39
require.Nil(t, out)
40
}
41
}
42
43