-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfileWriter_test.go
93 lines (86 loc) · 1.81 KB
/
fileWriter_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
package main
import (
"path/filepath"
"reflect"
"testing"
)
func TestFileWriter_Append(t *testing.T) {
tmpdir := t.TempDir()
t.Log(tmpdir)
fileWriter := NewFileWriter(
filepath.Join(tmpdir, "movies"),
[]string{"movieId", "title", "genres"},
)
tests := []struct {
name string
writer *FileWriter
args []Tuple
wantErr bool
}{
{
name: "movies1",
writer: fileWriter,
args: []Tuple{
{
Values: []Value{{
Name: "movieId",
StringValue: "1",
}, {
Name: "title",
StringValue: "Toy Story",
}, {
Name: "genres",
StringValue: "Adventure",
}},
},
{
Values: []Value{{
Name: "movieId",
StringValue: "2",
}, {
Name: "title",
StringValue: "Jumanji",
}, {
Name: "genres",
StringValue: "Adventure",
}},
},
{
Values: []Value{{
Name: "movieId",
StringValue: "3",
}, {
Name: "title",
StringValue: "Grumpe",
}, {
Name: "genres",
StringValue: "Romance",
}},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, tuple := range tt.args {
if err := fileWriter.Append(tuple); (err != nil) != tt.wantErr {
t.Errorf("FileWriter.Append() error = %v, wantErr %v", err, tt.wantErr)
}
}
fileScanOperator := NewFileScanOperator("movies", tmpdir, nil)
readTuples := []Tuple{}
for fileScanOperator.Next() {
readTuples = append(readTuples, fileScanOperator.Execute())
}
if !reflect.DeepEqual(tt.args, readTuples) {
t.Errorf("tuples read from disk %v are not the same as written to disk %v",
readTuples, tt.args,
)
}
})
}
t.Cleanup(func() {
// time.Sleep(50 * time.Second)
})
}