forked from Rheisen/bconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_condition_builder_test.go
53 lines (41 loc) · 1.29 KB
/
field_condition_builder_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 bconf_test
import (
"testing"
"github.com/rheisen/bconf"
)
func TestFieldConditionBuilderCreate(t *testing.T) {
builder := &bconf.FieldConditionBuilder{}
condition := builder.Create()
if condition == nil {
t.Fatalf("unexpected nil condition")
}
condition = bconf.NewFieldConditionBuilder().Create()
if condition == nil {
t.Fatalf("unexpected nil condition")
}
condition = bconf.FCB().Create()
if condition == nil {
t.Fatalf("unexpected nil condition")
}
}
func TestFieldConditionBuilderKeys(t *testing.T) {
const fieldSetKey = "test_field_set_key"
const fieldKey = "test_field_key"
condition := bconf.FCB().FieldSetKey(fieldSetKey).Create()
if fsKey, _ := condition.FieldDependency(); fsKey != fieldSetKey {
t.Fatalf("unexpected field-set key value '%s', expected '%s'", fsKey, fieldSetKey)
}
condition = bconf.FCB().FieldKey(fieldKey).Create()
if _, fKey := condition.FieldDependency(); fKey != fieldKey {
t.Fatalf("unexpected field key value '%s', expected '%s'", fKey, fieldKey)
}
}
func TestFieldConditionBuilderCondition(t *testing.T) {
condition := func(fieldValue any) (bool, error) {
return true, nil
}
fieldCondition := bconf.FCB().Condition(condition).Create()
if ok, _ := fieldCondition.Load(nil); !ok {
t.Fatalf("unexpected load value: %v", ok)
}
}