This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
attrs_test.go
69 lines (61 loc) · 1.86 KB
/
attrs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2022 Blockdaemon Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pyth
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAttrsMap(t *testing.T) {
caseMap := map[string]string{
"1pythians": "are",
"2incredibly": "based",
}
attrs, err := NewAttrsMap(caseMap)
require.NoError(t, err)
assert.Equal(t, [][2]string{
{"1pythians", "are"},
{"2incredibly", "based"},
}, attrs.Pairs)
assert.Equal(t, caseMap, attrs.KVs())
buf, err := attrs.MarshalBinary()
require.NoError(t, err)
assert.Equal(t, []byte(
"\x09"+"1pythians"+"\x03"+"are"+
"\x0b"+"2incredibly"+"\x05"+"based",
), buf)
var attrs2 AttrsMap
require.NoError(t, attrs2.UnmarshalBinary(buf))
assert.Equal(t, attrs, attrs2)
}
func TestAttrsMap_LongKey(t *testing.T) {
longKey := strings.Repeat("A", 256)
caseMap := map[string]string{
longKey: ":)",
}
attrs, err := NewAttrsMap(caseMap)
assert.EqualError(t, err, `key too long (256 > 0xFF): "`+longKey+`"`)
assert.Len(t, attrs.Pairs, 0)
assert.Len(t, attrs.KVs(), 0)
}
func TestAttrsMap_LongValue(t *testing.T) {
caseMap := map[string]string{
"bla": strings.Repeat("A", 256),
}
attrs, err := NewAttrsMap(caseMap)
assert.EqualError(t, err, `value too long (256 > 0xFF): "`+caseMap["bla"]+`"`)
assert.Len(t, attrs.Pairs, 0)
assert.Len(t, attrs.KVs(), 0)
}