-
Notifications
You must be signed in to change notification settings - Fork 21
/
t2_test.go
106 lines (93 loc) · 2.5 KB
/
t2_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
package ftdc
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
)
func TestTranslateGennyIntegration(t *testing.T) {
for _, test := range []struct {
name string
path string
skipSlow bool
skipAll bool
expectedNum int
expectedChunks int
expectedMetrics int
reportInterval int
docLen int
}{
{
name: "GennyMock",
path: "genny_metrics.ftdc",
docLen: 4,
expectedNum: 9,
expectedChunks: 1,
expectedMetrics: 300,
reportInterval: 1000,
skipSlow: true,
},
} {
t.Run(test.name, func(t *testing.T) {
file, err := os.Open(test.path)
require.NoError(t, err)
defer func() { printError(file.Close()) }()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
data, err := ioutil.ReadAll(file)
require.NoError(t, err)
var mockSlice []*GennyOutputMetadata
var mockGennyMetadata GennyOutputMetadata
mockGennyMetadata.StartTime = 1625003933
mockGennyMetadata.EndTime = 1625004233
mockGennyMetadata.Name = "test"
t.Run("Translate", func(t *testing.T) {
//setup metadata
iter := ReadChunks(ctx, bytes.NewBuffer(data))
mockGennyMetadata.Iter = iter
startAt := time.Now()
out := &bytes.Buffer{}
err := TranslateGenny(ctx, append(mockSlice, &mockGennyMetadata), out)
require.NoError(t, err)
// verify output
iter = ReadChunks(ctx, out)
counter := 0
num := 0
lastChunk := false
for iter.Next() {
c := iter.Chunk()
counter++
if num == 0 {
num = len(c.Metrics)
require.Equal(t, test.expectedNum, num)
}
metric := c.Metrics[rand.Intn(num)]
require.True(t, len(metric.Values) > 0)
assert.Equal(t, metric.startingValue, metric.Values[0], "key=%s", metric.Key())
// only check length of values if it's not the last chunk
if len(metric.Values) < test.expectedMetrics {
require.Equal(t, false, lastChunk)
lastChunk = true
}
if !lastChunk {
assert.Len(t, metric.Values, test.expectedMetrics, "%d: %d", len(metric.Values), test.expectedMetrics)
}
}
assert.NoError(t, iter.Err())
assert.Equal(t, test.expectedNum, num)
assert.Equal(t, test.expectedChunks, counter)
fmt.Println(testMessage{
"series": num,
"iters": counter,
"dur_secs": time.Since(startAt).Seconds(),
})
})
})
}
}