-
Notifications
You must be signed in to change notification settings - Fork 40
/
file_test.go
53 lines (40 loc) · 1.1 KB
/
file_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
// 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 (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
// mockFile creates an imagecashletter file
func mockFile(t *testing.T) *File {
t.Helper()
f := NewFile()
f.SetHeader(mockFileHeader())
clh := mockCashLetterHeader()
mockCashLetter := NewCashLetter(clh)
mockCashLetter.CashLetterControl = mockCashLetterControl()
f.AddCashLetter(mockCashLetter)
require.NoError(t, f.Create())
return f
}
func TestFileCreate(t *testing.T) {
file := mockFile(t)
require.NoError(t, file.Validate())
}
func TestFile_FileFromJSON(t *testing.T) {
bs, err := os.ReadFile(filepath.Join("test", "testdata", "icl-valid.json"))
require.NoError(t, err)
file, err := FileFromJSON(bs)
require.NoError(t, err)
require.NoError(t, file.Validate())
// error conditions
f, err := FileFromJSON(nil)
require.Nil(t, f)
require.Error(t, err)
f, err = FileFromJSON([]byte(`{invalid-json`))
require.Nil(t, f)
require.Error(t, err)
}