-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation_test.go
51 lines (44 loc) · 1.08 KB
/
validation_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 verdeter_test
import (
"fmt"
"testing"
"github.com/ditrit/verdeter"
"github.com/stretchr/testify/assert"
)
func TestValidateParent(t *testing.T) {
cfgParent := verdeter.NewVerdeterCommand(
"parent",
"a test command",
"whatever",
func(cfg *verdeter.VerdeterCommand, args []string) error {
fmt.Printf("args=%v", args)
return nil
},
)
cfgParent.GKey("firstLevel", verdeter.IsStr, "", "first level")
cfgParent.SetRequired("firstLevel")
cfgChild := verdeter.NewVerdeterCommand(
"clid",
"a test command",
"whatever",
func(cfg *verdeter.VerdeterCommand, args []string) error {
fmt.Printf("args=%v", args)
return nil
},
)
cfgParent.AddSubCommand(cfgChild)
assert.Error(t, cfgChild.Validate(true))
}
func TestConstraint(t *testing.T) {
cfgParent := verdeter.NewVerdeterCommand(
"parent",
"a test command",
"whatever",
func(cfg *verdeter.VerdeterCommand, args []string) error {
fmt.Printf("args=%v", args)
return nil
},
)
cfgParent.SetConstraint("failing constraint", func() bool { return false })
assert.Error(t, cfgParent.Validate(true))
}