-
Notifications
You must be signed in to change notification settings - Fork 40
/
validators_test.go
67 lines (53 loc) · 1.99 KB
/
validators_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
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package imagecashletter
import (
"fmt"
"math"
"testing"
"github.com/stretchr/testify/require"
)
func TestValidSize(t *testing.T) {
require.True(t, validSizeInt(10))
require.True(t, validSizeInt(1e7))
require.False(t, validSizeInt(1e8+1))
require.False(t, validSizeInt(1e9))
require.False(t, validSizeInt(math.MaxInt))
t.Run("converters", func(t *testing.T) {
c := &converters{}
// Do nothing if the request is too large
require.Equal(t, "", c.alphaField("a", 1e9))
require.Equal(t, "", c.numericField(7, 1e9))
require.Equal(t, "", c.nbsmField("b", 1e9))
require.Equal(t, "", c.stringField("c", 1e9))
})
t.Run("don't grow", func(t *testing.T) {
cdAddendumB := &CheckDetailAddendumB{}
cdAddendumB.LengthImageReferenceKey = fmt.Sprintf("%0.0f", 1e9)
require.Equal(t, "0 1000 ", cdAddendumB.String())
ivData := &ImageViewData{}
ivData.LengthImageReferenceKey = fmt.Sprintf("%0.0f", 1e9)
ivData.LengthDigitalSignature = fmt.Sprintf("%0.0f", 1e9)
ivData.LengthImageData = fmt.Sprintf("%0.0f", 1e9)
expected := "00000000000010101 0 1000100001000000"
require.Equal(t, expected, ivData.String())
rdAddendumC := &ReturnDetailAddendumC{}
rdAddendumC.LengthImageReferenceKey = fmt.Sprintf("%0.0f", 1e9)
expected = "0 1000 "
require.Equal(t, expected, rdAddendumC.String())
ug := &UserGeneral{}
ug.LengthUserData = fmt.Sprintf("%0.0f", 1e9)
expected = "0 1000000"
require.Equal(t, expected, ug.String())
})
t.Run("int", func(t *testing.T) {
require.False(t, validSizeInt(int(1e9)))
})
t.Run("uint", func(t *testing.T) {
a := uint(100)
b := uint(201)
require.False(t, validSizeUint(a-b))
require.True(t, validSizeUint(b-a))
})
}