Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package test |
||
2 | |||
3 | import ( |
||
4 | "testing" |
||
5 | |||
6 | "github.com/muonsoft/validation" |
||
7 | "github.com/muonsoft/validation/it" |
||
8 | "github.com/muonsoft/validation/validationtest" |
||
9 | "github.com/muonsoft/validation/validator" |
||
10 | "github.com/stretchr/testify/assert" |
||
11 | ) |
||
12 | |||
13 | func TestWhenGlobalValidatorWithOverriddenNewViolation_ExpectCustomViolation(t *testing.T) { |
||
14 | err := validator.SetOptions(validation.SetViolationFactory(mockNewViolationFunc())) |
||
15 | if err != nil { |
||
16 | t.Fatal(err) |
||
17 | } |
||
18 | defer validator.Reset() |
||
19 | |||
20 | err = validator.ValidateString(nil, it.IsNotBlank()) |
||
21 | |||
22 | validationtest.AssertIsViolationList(t, err, func(t *testing.T, violations validation.ViolationList) bool { |
||
23 | t.Helper() |
||
24 | return assert.Len(t, violations, 1) && assert.IsType(t, &mockViolation{}, violations[0]) |
||
25 | }) |
||
26 | } |
||
27 | |||
28 | func TestWhenValidatorWithOverriddenNewViolation_ExpectCustomViolation(t *testing.T) { |
||
29 | v := newValidator(t, validation.SetViolationFactory(mockNewViolationFunc())) |
||
30 | |||
31 | err := v.ValidateString(nil, it.IsNotBlank()) |
||
32 | |||
33 | validationtest.AssertIsViolationList(t, err, func(t *testing.T, violations validation.ViolationList) bool { |
||
34 | t.Helper() |
||
35 | return assert.Len(t, violations, 1) && assert.IsType(t, &mockViolation{}, violations[0]) |
||
36 | }) |
||
38 |