-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchunk_logger_test.go
89 lines (77 loc) · 2.21 KB
/
chunk_logger_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
package conveyor_test
import (
"bytes"
"errors"
"log"
"testing"
"github.com/fgehrlicher/conveyor"
"github.com/stretchr/testify/assert"
)
func TestLogChunkResult(t *testing.T) {
assertion := assert.New(t)
loggerOutput := bytes.Buffer{}
errorLoggerOutput := bytes.Buffer{}
queue := conveyor.NewQueue(
generateTestChunks(100, 1024, chunkTestFile),
1,
nil,
&conveyor.QueueOpts{
Logger: log.New(&loggerOutput, "", 0),
ErrLogger: log.New(&errorLoggerOutput, "", 0),
},
)
tt := []struct {
ChunkResult conveyor.ChunkResult
currentChunkCount int
ExpectedOutput string
ExpectedErrorOutput string
}{
{
ChunkResult: conveyor.ChunkResult{Chunk: conveyor.Chunk{Id: 1}, Lines: 100},
currentChunkCount: 1,
ExpectedOutput: "[ 1/100] 1.00 % done. lines: 100\n",
},
{
ChunkResult: conveyor.ChunkResult{Chunk: conveyor.Chunk{Id: 10}, Lines: 100},
currentChunkCount: 10,
ExpectedOutput: "[ 10/100] 10.00 % done. lines: 100\n",
},
{
ChunkResult: conveyor.ChunkResult{Chunk: conveyor.Chunk{Id: 50}, Lines: 100},
currentChunkCount: 50,
ExpectedOutput: "[ 50/100] 50.00 % done. lines: 100\n",
},
{
ChunkResult: conveyor.ChunkResult{Chunk: conveyor.Chunk{Id: 99}, Lines: 100},
currentChunkCount: 99,
ExpectedOutput: "[ 99/100] 99.00 % done. lines: 100\n",
},
{
ChunkResult: conveyor.ChunkResult{Chunk: conveyor.Chunk{Id: 100}, Lines: 100},
currentChunkCount: 100,
ExpectedOutput: "[100/100] 100.00 % done. lines: 100\n",
},
{
ChunkResult: conveyor.ChunkResult{
Chunk: conveyor.Chunk{Id: 10},
Lines: 100,
Err: errors.New("chunk error: test error"),
},
currentChunkCount: 10,
ExpectedErrorOutput: "[ 10/100] chunk error: test error\n",
},
}
for _, test := range tt {
loggerOutput.Reset()
errorLoggerOutput.Reset()
conveyor.LogChunkResult(queue, test.ChunkResult, test.currentChunkCount)
if test.ExpectedOutput != "" {
loggerOut := loggerOutput.String()
assertion.Equal(test.ExpectedOutput, loggerOut)
}
if test.ExpectedErrorOutput != "" {
errLoggerOut := errorLoggerOutput.String()
assertion.Equal(test.ExpectedErrorOutput, errLoggerOut)
}
}
}