forked from maksymgaraiev/orwell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xgtandor_test.go
45 lines (42 loc) · 1.66 KB
/
xgtandor_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
package orwell
import (
"testing"
)
func TestApplyXGtAndOr(t *testing.T) {
t.Run("gtField > gtValue, andValue not empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 9, and: "not nil", ors: nil}
if err := r.Apply("not nil"); err != nil {
t.Error("Expected valid because validated value is not nil ")
}
})
t.Run("gtField > gtValue, andValue not empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 9, and: "not nil", ors: nil}
if err := r.Apply(nil); err == nil {
t.Error("Expected error because validated value is nil")
}
})
t.Run("gtField > gtValue, andValue is empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 9, and: nil, ors: nil}
if err := r.Apply(nil); err != nil {
t.Error("Expected valid because andValue is nil")
}
})
t.Run("gtField > gtValue, andValue is empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 9, and: "", ors: nil}
if err := r.Apply(nil); err != nil {
t.Error("Expected valid because andValue is empty")
}
})
t.Run("gtField = gtValue, andValue not empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 10, and: "not nil", ors: nil}
if err := r.Apply(nil); err != nil {
t.Error("Expected valid because gtField is not greater than gtValue")
}
})
t.Run("gtField > gtValue, andValue not empty, ors nil, value not nil", func(t *testing.T) {
r := &xGtAndOr{gtField: 10, gtValue: 9, and: "not nil", ors: []interface{}{"test"}}
if err := r.Apply(nil); err != nil {
t.Error("Expected valid because ors is not empty")
}
})
}