-
Notifications
You must be signed in to change notification settings - Fork 0
/
expression_test.go
51 lines (42 loc) · 1.23 KB
/
expression_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
package kite_go
import (
"github.com/stretchr/testify/assert"
"gopkg.in/Knetic/govaluate.v3"
"testing"
)
func TestGetExpressionToken(t *testing.T) {
expression, err := govaluate.NewEvaluableExpression("appVersion>='9.0.1'&&appVersion<='10.0.1'")
assert.Nil(t, err)
tokens := GetExpressionToken(expression)
assert.Equal(t, 2, len(tokens))
assert.Equal(t, tokens[0].Name, "appVersion")
assert.Equal(t, tokens[0].Comparator, ">=")
assert.Equal(t, tokens[0].Operator, "&&")
assert.Equal(t, tokens[0].Value, "9.0.1")
assert.Equal(t, tokens[1].Name, "appVersion")
assert.Equal(t, tokens[1].Comparator, "<=")
assert.Equal(t, tokens[1].Operator, "")
assert.Equal(t, tokens[1].Value, "10.0.1")
}
func TestGetVersionsFromRequest(t *testing.T) {
requestParam := map[string]interface{}{
"appVersion": "10.9.1",
"homeVersion": "10.9.1",
"platform": "android",
}
variable1 := Variable{
Name: "appVersion",
Type: Version,
Value: "10.9.1",
}
variable2 := Variable{
Name: "homeVersion",
Type: Version,
Value: "10.9.1",
}
var variables []Variable
variables = append(variables, variable1)
variables = append(variables, variable2)
versions := GetVersionsFromRequest(requestParam, variables)
assert.Len(t, versions, 2)
}