Path: blob/main/pkg/metrics/instance/configstore/codec_test.go
5327 views
package configstore12import (3"testing"45"github.com/stretchr/testify/require"6)78func TestCodec(t *testing.T) {9exampleConfig := `name: 'test'10host_filter: false11scrape_configs:12- job_name: process-113static_configs:14- targets: ['process-1:80']15labels:16cluster: 'local'17origin: 'agent'`1819c := &yamlCodec{}20bb, err := c.Encode(exampleConfig)21require.NoError(t, err)2223out, err := c.Decode(bb)24require.NoError(t, err)25require.Equal(t, exampleConfig, out)26}2728// TestCodec_Decode_Nil makes sure that if Decode is called with an empty value,29// which may happen when a key is deleted, that no error occurs and instead a30// nil value is returned.31func TestCodec_Decode_Nil(t *testing.T) {32c := &yamlCodec{}3334input := [][]byte{nil, make([]byte, 0)}35for _, bb := range input {36out, err := c.Decode(bb)37require.Nil(t, err)38require.Nil(t, out)39}40}414243