# 207 test coverage writer_test.go
# 207 test coverage writer_test.go
@@ -49,10 +49,57 @@ func TestPPDWrite(t *testing.T) {
testPPDWrite(t)
}
-// BenchmarkPPDWrite benchmarks writing a PPD ACH file
+// BenchmarkPPDWrite benchmarks validating writing a PPD ACH file
func BenchmarkPPDWrite(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
testPPDWrite(b)
}
}
+
+// testFileWriteErr validates error for file write
+func testFileWriteErr(t testing.TB) {
+ file := NewFile().SetHeader(mockFileHeader())
+ entry := mockEntryDetail()
+ entry.AddAddenda(mockAddenda05())
+ batch := NewBatchPPD(mockBatchPPDHeader())
+ batch.SetHeader(mockBatchHeader())
+ batch.AddEntry(entry)
+ batch.Create()
+ file.AddBatch(batch)
+
+ if err := file.Create(); err != nil {
+ t.Errorf("%T: %s", err, err)
+ }
+ if err := file.Validate(); err != nil {
+ t.Errorf("%T: %s", err, err)
+ }
+
+ file.Batches[0].GetControl().EntryAddendaCount = 10
+
+ b := &bytes.Buffer{}
+ f := NewWriter(b)
+
+ if err := f.WriteAll([]*File{file}); err != nil {
+ if e, ok := err.(*FileError); ok {
+ if e.FieldName != "EntryAddendaCount" {
+ t.Errorf("%T: %s", err, err)
+ }
+ } else {
+ t.Errorf("%T: %s", err, err)
+ }
+ }
+}
+
+// TestFileWriteErr tests validating error for file write
+func TestFileWriteErr(t *testing.T) {
+ testFileWriteErr(t)
+}
+
+// BenchmarkFileWriteErr benchmarks error for file write
+func BenchmarkFileWriteErr(b *testing.B) {
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ testFileWriteErr(b)
+ }
+}
