-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_bool_test.go
42 lines (38 loc) · 1.09 KB
/
gen_bool_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
package fauxrpc_test
import (
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/reflect/protoreflect"
"github.com/sudorandom/fauxrpc"
)
func TestBool(t *testing.T) {
testCases := []struct {
name string
fd protoreflect.FieldDescriptor
expected []bool
}{
{
name: "always return true",
fd: mustCompileField("bool", "bool_val", ""),
expected: []bool{true},
},
{
name: "const constraint set to true",
fd: mustCompileField("bool", "bool_val", "(buf.validate.field).bool.const = true"),
expected: []bool{true},
},
// TODO: Debug why constraints don't appear to be showing up for the field descriptors generated
// in this way.
// {
// name: "const constraint set to false",
// fd: mustCompileField("bool", "bool_val", "(buf.validate.field).bool.const = false"),
// expected: []bool{false},
// },
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := fauxrpc.Bool(tc.fd, fauxrpc.GenOptions{})
assert.Contains(t, tc.expected, result, "unexpected value")
})
}
}