-
Notifications
You must be signed in to change notification settings - Fork 1
/
amount_test.go
69 lines (50 loc) · 1.55 KB
/
amount_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
package wire
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockAmount creates an a Amount
func mockAmount() *Amount {
a := NewAmount()
a.Amount = "000001234567"
return a
}
// TestMockAmount validates mockAmount
func TestMockAmount(t *testing.T) {
a := mockAmount()
require.NoError(t, a.Validate(), "mockAmount does not validate and will break other tests")
}
// TestAmountValid validates Amount
func TestAmountValid(t *testing.T) {
a := mockAmount()
a.Amount = "X,"
err := a.Validate()
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, a.Amount).Error())
}
// TestAmountRequired validates Amount is required
func TestAmountRequired(t *testing.T) {
a := mockAmount()
a.Amount = ""
err := a.Validate()
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}
// TestParseAmountReaderParseError parses a wrong Amount reader parse error
func TestParseAmountReaderParseError(t *testing.T) {
var line = "{2000}00000Z030022"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseAmount()
expected := r.parseError(fieldError("Amount", ErrNonAmount, "00000Z030022")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("Amount", ErrNonAmount, "00000Z030022")).Error()
require.EqualError(t, err, expected)
}
// TestAmountTagError validates Amount tag
func TestAmountTagError(t *testing.T) {
a := mockAmount()
a.tag = "{9999}"
err := a.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, a.tag).Error())
}