-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcases_oneof.go
99 lines (96 loc) · 3.56 KB
/
cases_oneof.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cases
import (
"github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate"
"github.com/bufbuild/protovalidate/tools/internal/gen/buf/validate/conformance/cases"
"github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/results"
"github.com/bufbuild/protovalidate/tools/protovalidate-conformance/internal/suites"
)
func oneofSuite() suites.Suite {
return suites.Suite{
"none/valid": {
Message: &cases.OneofNone{O: &cases.OneofNone_X{X: "foo"}},
Expected: results.Success(true),
},
"none/empty/valid": {
Message: &cases.OneofNone{},
Expected: results.Success(true),
},
"field/X/valid": {
Message: &cases.Oneof{O: &cases.Oneof_X{X: "foobar"}},
Expected: results.Success(true),
},
"field/Y/valid": {
Message: &cases.Oneof{O: &cases.Oneof_Y{Y: 123}},
Expected: results.Success(true),
},
"field/Z/valid": {
Message: &cases.Oneof{O: &cases.Oneof_Z{Z: &cases.TestOneofMsg{Val: true}}},
Expected: results.Success(true),
},
"field/empty/valid": {
Message: &cases.Oneof{},
Expected: results.Success(true),
},
"field/X/invalid": {
Message: &cases.Oneof{O: &cases.Oneof_X{X: "fizzbuzz"}},
Expected: results.Violations(&validate.Violation{FieldPath: "x", ConstraintId: "string.prefix"}),
},
"field/Y/invalid": {
Message: &cases.Oneof{O: &cases.Oneof_Y{Y: -1}},
Expected: results.Violations(&validate.Violation{FieldPath: "y", ConstraintId: "int32.gt"}),
},
"filed/Z/invalid": {
Message: &cases.Oneof{O: &cases.Oneof_Z{Z: &cases.TestOneofMsg{}}},
Expected: results.Violations(&validate.Violation{FieldPath: "z.val", ConstraintId: "bool.const"}),
},
"required/valid/empty": {
Message: &cases.OneofRequired{O: &cases.OneofRequired_X{X: ""}},
Expected: results.Success(true),
},
"required/valid/non-empty": {
Message: &cases.OneofRequired{O: &cases.OneofRequired_X{X: "foo"}},
Expected: results.Success(true),
},
"required/invalid": {
Message: &cases.OneofRequired{},
Expected: results.Violations(&validate.Violation{FieldPath: "o", ConstraintId: "required"}),
},
"required/required_field/valid/empty": {
Message: &cases.OneofRequiredWithRequiredField{
O: &cases.OneofRequiredWithRequiredField_A{A: ""},
},
Expected: results.Success(true),
},
"required/required_field/valid/non-empty": {
Message: &cases.OneofRequiredWithRequiredField{
O: &cases.OneofRequiredWithRequiredField_A{A: "foo"},
},
Expected: results.Success(true),
},
"required/required_field/wrong_field": {
Message: &cases.OneofRequiredWithRequiredField{
O: &cases.OneofRequiredWithRequiredField_B{B: "foo"},
},
Expected: results.Violations(&validate.Violation{FieldPath: "a", ConstraintId: "required"}),
},
"required/required_field/invalid": {
Message: &cases.OneofRequiredWithRequiredField{},
Expected: results.Violations(
&validate.Violation{FieldPath: "o", ConstraintId: "required"},
&validate.Violation{FieldPath: "a", ConstraintId: "required"}),
},
}
}