forked from csimplestring/delta-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkpoint_test.go
141 lines (104 loc) · 3.13 KB
/
checkpoint_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package deltago_test
import (
"fmt"
"io"
"testing"
delta "github.com/csimplestring/delta-go"
"github.com/rotisserie/eris"
"github.com/samber/mo"
"github.com/csimplestring/delta-go/iter"
"github.com/csimplestring/delta-go/store"
"github.com/stretchr/testify/assert"
)
func TestFindLastCompleteCheckpoint(t *testing.T) {
s, err := newMemLogStore()
assert.NoError(t, err)
t.Run("returns err when first call to iterator fails with an error different from io.EOF", func(t *testing.T) {
t.Cleanup(s.reset)
callFailure := fmt.Errorf("RequestError: send request failed")
failIf = func() (bool, error) {
return true, callFailure
}
lastCheckpoint, err := delta.FindLastCompleteCheckpoint(s, delta.MaxInstance)
assert.Equal(t, lastCheckpoint, mo.None[*delta.CheckpointInstance]())
assert.Equal(t, err.Error(), eris.Wrap(callFailure, "").Error())
})
t.Run("returns err when any call to iterator fails with an error different from io.EOF", func(t *testing.T) {
t.Cleanup(s.reset)
callFailure := fmt.Errorf("RequestError: send request failed")
var n int
failIf = func() (bool, error) {
n++
if n == 3 {
return true, callFailure
}
return false, nil
}
lastCheckpoint, err := delta.FindLastCompleteCheckpoint(s, delta.MaxInstance)
assert.Equal(t, lastCheckpoint, mo.None[*delta.CheckpointInstance]())
assert.Equal(t, err.Error(), eris.Wrap(callFailure, "").Error())
})
t.Run("returns no err when io.EOF is returned", func(t *testing.T) {
t.Cleanup(s.reset)
var n int
failIf = func() (bool, error) {
n++
if n == 2 {
return true, io.EOF
}
return false, nil
}
lastCheckpoint, err := delta.FindLastCompleteCheckpoint(s, delta.MaxInstance)
assert.Equal(t, lastCheckpoint, mo.None[*delta.CheckpointInstance]())
assert.Equal(t, err, nil)
})
}
func newMemLogStore() (*memLogStore, error) {
return &memLogStore{}, nil
}
type memLogStore struct {
mustFail func() (bool, error)
}
func (s *memLogStore) reset() {
s.mustFail = func() (bool, error) { return false, nil }
}
func (s *memLogStore) Root() string {
return ""
}
func (s *memLogStore) Read(path string) (iter.Iter[string], error) {
return nil, fmt.Errorf("not implemented")
}
var failIf func() (bool, error)
func (s *memLogStore) ListFrom(path string) (iter.Iter[*store.FileMeta], error) {
return &memIter{
mustFail: failIf,
}, nil
}
type memIter struct {
mustFail func() (bool, error)
}
func (i *memIter) Next() (*store.FileMeta, error) {
fail, err := i.mustFail()
if fail {
return nil, err
}
return &store.FileMeta{}, nil
}
func (i *memIter) Close() error {
return fmt.Errorf("not implemented")
}
func (s *memLogStore) Write(path string, actions iter.Iter[string], overwrite bool) error {
return fmt.Errorf("not implemented")
}
func (s *memLogStore) ResolvePathOnPhysicalStore(path string) (string, error) {
return "", fmt.Errorf("not implemented")
}
func (s *memLogStore) IsPartialWriteVisible(path string) bool {
return false
}
func (s *memLogStore) Exists(path string) (bool, error) {
return false, fmt.Errorf("not implemented")
}
func (s *memLogStore) Create(path string) error {
return fmt.Errorf("not implemented")
}