-
Notifications
You must be signed in to change notification settings - Fork 3
/
stream_panic_test.go
121 lines (106 loc) · 2.43 KB
/
stream_panic_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package filetypes
import (
"errors"
"io"
"testing"
"github.com/apache/arrow/go/v17/arrow"
"github.com/apache/arrow/go/v17/arrow/array"
"github.com/apache/arrow/go/v17/arrow/memory"
"github.com/cloudquery/filetypes/v4/types"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/stretchr/testify/require"
)
func TestPanicOnHeader(t *testing.T) {
r := require.New(t)
cl := &Client{
spec: &FileSpec{
Compression: CompressionTypeNone,
},
filetype: &customWriter{
PanicOnHeader: true,
},
}
stream, err := cl.StartStream(&schema.Table{}, func(io.Reader) error {
return nil
})
r.Nil(stream)
r.Error(err)
r.ErrorContains(err, "panic:")
}
func TestPanicOnWrite(t *testing.T) {
r := require.New(t)
cl := &Client{
spec: &FileSpec{
Compression: CompressionTypeNone,
},
filetype: &customWriter{
PanicOnWrite: true,
},
}
table := &schema.Table{
Name: "test",
Columns: []schema.Column{
{Name: "name", Type: arrow.BinaryTypes.String},
},
}
bldr := array.NewRecordBuilder(memory.DefaultAllocator, table.ToArrowSchema())
bldr.Field(0).(*array.StringBuilder).Append("foo")
bldr.Field(0).(*array.StringBuilder).Append("bar")
record := bldr.NewRecord()
stream, err := cl.StartStream(table, func(io.Reader) error {
return nil
})
r.NoError(err)
err = stream.Write([]arrow.Record{record})
r.Error(err)
r.ErrorContains(err, "panic:")
r.NoError(stream.Finish())
}
func TestPanicOnClose(t *testing.T) {
r := require.New(t)
cl := &Client{
spec: &FileSpec{
Compression: CompressionTypeNone,
},
filetype: &customWriter{
PanicOnClose: true,
},
}
stream, err := cl.StartStream(&schema.Table{}, func(io.Reader) error {
return nil
})
r.NoError(err)
r.NoError(stream.Write(nil))
err = stream.Finish()
r.Error(err)
r.ErrorContains(err, "panic:")
}
type customWriter struct {
PanicOnHeader bool
PanicOnWrite bool
PanicOnClose bool
}
type customHandle struct {
w *customWriter
}
func (w *customWriter) WriteHeader(io.Writer, *schema.Table) (types.Handle, error) {
if w.PanicOnHeader {
panic("test panic")
}
return &customHandle{w: w}, nil
}
func (*customWriter) Read(types.ReaderAtSeeker, *schema.Table, chan<- arrow.Record) error {
return errors.New("not implemented")
}
func (h *customHandle) WriteContent([]arrow.Record) error {
if h.w.PanicOnWrite {
panic("test panic")
}
return nil
}
func (h *customHandle) WriteFooter() error {
if h.w.PanicOnClose {
panic("test panic")
}
return nil
}