-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstream_test.go
50 lines (41 loc) · 1.01 KB
/
stream_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
package cmd_test
import (
"context"
"os"
"testing"
"github.com/rockset/rockset-go-client/openapi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/rockset/cli/cmd"
"github.com/rockset/cli/flag"
)
func TestStreamDocuments(t *testing.T) {
ctx := context.TODO()
//in := bytes.NewBufferString(`{}`)
in, err := os.Open("testdata/test.json")
require.NoError(t, err)
f := &fake{t}
s := cmd.NewStreamer(f, cmd.StreamConfig{
Workspace: flag.DefaultWorkspace,
Collection: "writetest",
BatchSize: 3,
})
cnt, err := s.Stream(ctx, in)
require.NoError(t, err)
assert.Equal(t, uint64(5), cnt)
}
type fake struct {
t *testing.T
}
func (f *fake) AddDocuments(ctx context.Context, workspace, collection string,
docs []interface{}) ([]openapi.DocumentStatus, error) {
f.t.Logf("%d docs added", len(docs))
res := make([]openapi.DocumentStatus, len(docs))
added := "ADDED"
for i := range docs {
res[i] = openapi.DocumentStatus{
Status: &added,
}
}
return res, nil
}