(t *testing.T)
| 293 | } |
| 294 | |
| 295 | func TestCustomRuleSetWithRules(t *testing.T) { |
| 296 | someRule := validator.Rule{ |
| 297 | Name: "SomeRule", |
| 298 | RuleFunc: func(observers *validator.Events, addError validator.AddErrFunc) { |
| 299 | addError(validator.Message("%s", "some error message")) |
| 300 | }, |
| 301 | } |
| 302 | |
| 303 | someOtherRule := validator.Rule{ |
| 304 | Name: "SomeOtherRule", |
| 305 | RuleFunc: func(observers *validator.Events, addError validator.AddErrFunc) { |
| 306 | addError(validator.Message("%s", "some other error message")) |
| 307 | }, |
| 308 | } |
| 309 | |
| 310 | s := gqlparser.MustLoadSchema( |
| 311 | &ast.Source{ |
| 312 | Name: "graph/schema.graphqls", |
| 313 | Input: ` |
| 314 | type Query { |
| 315 | bar: String! |
| 316 | } |
| 317 | `, BuiltIn: false, |
| 318 | }, |
| 319 | ) |
| 320 | |
| 321 | q, err := parser.ParseQuery(&ast.Source{ |
| 322 | Name: "SomeQuery", |
| 323 | Input: ` |
| 324 | query Foo($flag: Boolean!) { |
| 325 | ...Bar |
| 326 | } |
| 327 | `, |
| 328 | }) |
| 329 | require.NoError(t, err) |
| 330 | errList := validator.ValidateWithRules(s, q, rules.NewRules(someRule, someOtherRule)) |
| 331 | require.Len(t, errList, 2) |
| 332 | |
| 333 | // because we hold rules in a map, the order is not guaranteed |
| 334 | // this is fine because we used to add the rule in the init function, so it didn't need to be |
| 335 | // specified as a requirement for the order. |
| 336 | messages := []string{errList[0].Message, errList[1].Message} |
| 337 | require.Contains(t, messages, "some error message") |
| 338 | require.Contains(t, messages, "some other error message") |
| 339 | } |
| 340 | |
| 341 | func TestRemoveRule(t *testing.T) { |
| 342 | // no error |
nothing calls this directly
no test coverage detected
searching dependent graphs…