-
Notifications
You must be signed in to change notification settings - Fork 2
/
commonConverters_test.go
57 lines (40 loc) · 1.16 KB
/
commonConverters_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
package logger
import (
"encoding/hex"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFormatMessage_ShouldOutputFixedOrLargerStringThanMsgFixedLength(t *testing.T) {
t.Parallel()
testData := make(map[string]int)
testData[""] = 40
testData["small string"] = 40
largeString := "large string: " + strings.Repeat("A", messageFixedLength)
testData[largeString] = len(largeString)
for k, v := range testData {
result := formatMessage(k)
assert.Equal(t, v, len(result))
}
}
func TestToHexShort_EmptySliceShouldReturnEmptyString(t *testing.T) {
t.Parallel()
hash := []byte("")
res := ToHexShort(hash)
assert.Equal(t, 0, len(res))
}
func TestToHexShort_SliceLengthSmallShouldNotChange(t *testing.T) {
t.Parallel()
input := []byte("short")
hexHash := hex.EncodeToString(input)
res := ToHexShort(input)
assert.Equal(t, hexHash, res)
}
func TestToHexShort_SliceLengthBigShouldTrim(t *testing.T) {
t.Parallel()
input := []byte("long enough input so it should be trimmed")
hexHash := hex.EncodeToString(input)
res := ToHexShort(input)
assert.NotEqual(t, len(hexHash), len(res))
assert.True(t, strings.Contains(res, ellipsisString))
}