@@ -5,12 +5,15 @@ package task_test
55import (
66 "archive/tar"
77 "bytes"
8+ "errors"
89 "fmt"
910 "reflect"
1011 "testing"
1112
1213 "cloud.google.com/go/bigquery"
1314
15+ "time"
16+
1417 "github.com/m-lab/etl/parser"
1518 "github.com/m-lab/etl/storage" // TODO - would be better not to have this.
1619 "github.com/m-lab/etl/task"
@@ -59,7 +62,7 @@ func MakeTestSource(t *testing.T) *storage.ETLSource {
5962 t .Fatal (err )
6063 }
6164
62- return & storage.ETLSource {tar .NewReader (b ), NullCloser {}}
65+ return & storage.ETLSource {tar .NewReader (b ), NullCloser {}, time . Millisecond }
6366}
6467
6568type TestParser struct {
@@ -83,8 +86,37 @@ func (tp *TestParser) ParseAndInsert(meta map[string]bigquery.Value, testName st
8386 return nil
8487}
8588
86- // TODO(dev) - add unit tests for tgz and tar.gz files
87- // TODO(dev) - add good comments
89+ type badSource struct {}
90+
91+ func (bs * badSource ) Next () (* tar.Header , error ) {
92+ return nil , errors .New ("Random Error" )
93+ }
94+ func (bs * badSource ) Read (b []byte ) (int , error ) {
95+ return 0 , errors .New ("Read error" )
96+ }
97+
98+ // TODO - this test is very slow, because it triggers the backoff and retry mechanism.
99+ func TestBadTarFileInput (t * testing.T ) {
100+ rdr := & storage.ETLSource {& badSource {}, NullCloser {}, time .Millisecond }
101+
102+ tp := & TestParser {}
103+
104+ // Among other things, this requires that tp implements etl.Parser.
105+ tt := task .NewTask ("filename" , rdr , tp )
106+ fc , err := tt .ProcessAllTests ()
107+ if err .Error () != "Random Error" {
108+ t .Error ("Expected Random Error, but got %v" , err )
109+ }
110+ // Should see 1 files.
111+ if fc != 1 {
112+ t .Error ("Expected 1 file: " , fc )
113+ }
114+ // ... but process none.
115+ if len (tp .files ) != 0 {
116+ t .Error ("Should have processed no files: " , len (tp .files ))
117+ }
118+ }
119+
88120func TestTarFileInput (t * testing.T ) {
89121 rdr := MakeTestSource (t )
90122
0 commit comments