1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
12
"github.com/stretchr/testify/assert"
13
"github.com/stretchr/testify/require"
15
"github.com/siderolabs/talos/pkg/machinery/meta"
18
func TestValue(t *testing.T) {
23
require.NoError(t, v.Parse("10=foo"))
25
assert.Equal(t, uint8(10), v.Key)
26
assert.Equal(t, "foo", v.Value)
28
assert.Equal(t, "0xa=foo", v.String())
32
require.NoError(t, v2.Parse(v.String()))
34
assert.Equal(t, v, v2)
37
func TestEncodeDecodeValues(t *testing.T) {
40
for _, allowGzip := range []bool{false, true} {
41
t.Run(fmt.Sprintf("allowGzip=%v", allowGzip), func(t *testing.T) {
44
for _, test := range []struct {
49
expectedEncodedSize int
50
expectedGzippedSize int
62
expectedEncodedSize: 20,
63
expectedGzippedSize: 20,
68
"10=" + strings.Repeat("foobar", 256),
69
"0xb=" + strings.Repeat("baz", 256),
72
expectedEncodedSize: 3084,
73
expectedGzippedSize: 80,
76
t.Run(test.name, func(t *testing.T) {
79
values := make(meta.Values, len(test.values))
81
for i, v := range test.values {
82
require.NoError(t, values[i].Parse(v))
89
encoded := values.Encode(allowGzip)
92
case test.expectedEncodedSize > 0 && !allowGzip:
93
assert.Equal(t, test.expectedEncodedSize, len(encoded))
94
case test.expectedGzippedSize > 0 && allowGzip:
95
assert.Equal(t, test.expectedGzippedSize, len(encoded))
98
decoded, err := meta.DecodeValues(encoded)
99
require.NoError(t, err)
101
assert.Equal(t, values, decoded)