Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package test |
||
2 | |||
3 | import ( |
||
4 | "errors" |
||
5 | "testing" |
||
6 | |||
7 | "github.com/muonsoft/validation" |
||
8 | "github.com/muonsoft/validation/validationtest" |
||
9 | "github.com/stretchr/testify/assert" |
||
10 | ) |
||
11 | |||
12 | func assertHasOneViolation(code, message, path string) func(t *testing.T, err error) { |
||
13 | return func(t *testing.T, err error) { |
||
14 | t.Helper() |
||
15 | validationtest.AssertIsViolationList(t, err, func(t *testing.T, violations validation.ViolationList) bool { |
||
16 | t.Helper() |
||
17 | |||
18 | if assert.Len(t, violations, 1) { |
||
19 | return assert.Equal(t, code, violations[0].Code()) && |
||
20 | assert.Equal(t, message, violations[0].Message()) && |
||
21 | assert.Equal(t, path, violations[0].PropertyPath().String()) |
||
22 | } |
||
23 | |||
24 | return false |
||
25 | }) |
||
26 | } |
||
27 | } |
||
28 | |||
29 | func assertNoError(t *testing.T, err error) { |
||
30 | t.Helper() |
||
31 | assert.NoError(t, err) |
||
32 | } |
||
33 | |||
34 | func assertIsInapplicableConstraintError(t *testing.T, err error, valueType string) { |
||
35 | t.Helper() |
||
36 | var inapplicableConstraint *validation.InapplicableConstraintError |
||
37 | |||
38 | if !errors.As(err, &inapplicableConstraint) { |
||
39 | t.Errorf("failed asserting that error is InapplicableConstraintError") |
||
40 | return |
||
41 | } |
||
42 | |||
43 | assert.Equal(t, valueType, inapplicableConstraint.ValueType) |
||
44 | } |
||
45 |