-
Notifications
You must be signed in to change notification settings - Fork 5
/
opts_test.go
53 lines (44 loc) · 1.45 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
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 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)
}