-
Notifications
You must be signed in to change notification settings - Fork 5
/
opts_test.go
66 lines (55 loc) · 1.96 KB
/
opts_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
package promqlsmith
import (
"testing"
"time"
"github.com/prometheus/prometheus/promql/parser"
"github.com/stretchr/testify/require"
)
func TestWithEnableOffset(t *testing.T) {
o := &options{}
WithEnableOffset(true).apply(o)
require.True(t, o.enableOffset)
}
func TestWithEnableAtModifier(t *testing.T) {
o := &options{}
WithEnableAtModifier(true).apply(o)
require.True(t, o.enableAtModifier)
}
func TestWithEnableExperimentalPromQL(t *testing.T) {
o := &options{}
WithEnableExperimentalPromQLFunctions(true).apply(o)
WithEnabledFunctions(nil).apply(o)
WithEnabledAggrs(nil).apply(o)
o.applyDefaults()
// check experimental aggrs and funcs are appended well
require.True(t, o.enableExperimentalPromQLFunctions)
require.Equal(t, len(defaultSupportedAggrs)+len(experimentalPromQLAggrs), len(o.enabledAggrs))
require.Equal(t, len(defaultSupportedFuncs)+len(experimentalSupportedFuncs), len(o.enabledFuncs))
}
func TestWithEnabledAggrs(t *testing.T) {
o := &options{}
WithEnabledAggrs([]parser.ItemType{parser.SUM}).apply(o)
require.Equal(t, []parser.ItemType{parser.SUM}, o.enabledAggrs)
}
func TestWithMaxAtModifierTimestamp(t *testing.T) {
o := &options{}
o.applyDefaults()
require.GreaterOrEqual(t, time.Now().UnixMilli(), o.atModifierMaxTimestamp)
WithAtModifierMaxTimestamp(time.UnixMilli(1000).UnixMilli()).apply(o)
require.Equal(t, int64(1000), o.atModifierMaxTimestamp)
}
func TestWithEnabledBinOps(t *testing.T) {
o := &options{}
WithEnabledBinOps([]parser.ItemType{parser.ADD}).apply(o)
require.Equal(t, []parser.ItemType{parser.ADD}, o.enabledBinops)
}
func TestWithEnabledExprs(t *testing.T) {
o := &options{}
WithEnabledExprs([]ExprType{VectorSelector}).apply(o)
require.Equal(t, []ExprType{VectorSelector}, o.enabledExprs)
}
func TestWithEnabledFunctions(t *testing.T) {
o := &options{}
WithEnabledFunctions([]*parser.Function{parser.Functions["absent"]}).apply(o)
require.Equal(t, []*parser.Function{parser.Functions["absent"]}, o.enabledFuncs)
}