-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_loader_test.go
45 lines (37 loc) · 900 Bytes
/
file_loader_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
package dbuf
import (
"io"
"io/ioutil"
"os"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFileLoader(t *testing.T) {
filePath := path.Join(t.TempDir(), t.Name())
f, err := os.Create(filePath)
assert.NoError(t, err)
_, _ = f.Write([]byte("abc"))
assert.NoError(t, f.Close())
fl := NewFileLoader(
LocalSingleFileLoadSystem,
filePath,
func(reader io.Reader, i interface{}) error {
content, _ := ioutil.ReadAll(reader)
s := i.(*string)
*s = string(content)
return nil
})
buffer := NewDoubleBuffer(fl, func() interface{} {
var s string
return &s
})
assert.True(t, buffer.load())
assert.EqualValues(t, "abc", *buffer.Data().(*string))
f, err = os.Create(filePath)
assert.NoError(t, err)
_, _ = f.Write([]byte("def"))
assert.NoError(t, f.Close())
assert.True(t, buffer.load())
assert.EqualValues(t, "def", *buffer.Data().(*string))
}