Passed
Push — main ( 2a46cd...12059c )
by Igor
01:41
created

test/validate_value_test.go   A

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 46
dl 0
loc 54
c 0
b 0
f 0
rs 10
1
package test
2
3
import (
4
	"testing"
5
6
	"github.com/muonsoft/validation"
7
	"github.com/muonsoft/validation/code"
8
	"github.com/muonsoft/validation/it"
9
	"github.com/muonsoft/validation/message"
10
	"github.com/muonsoft/validation/validationtest"
11
	"github.com/muonsoft/validation/validator"
12
	"github.com/stretchr/testify/assert"
13
)
14
15
func TestValidateValue_WhenValueOfType_ExpectValueValidated(t *testing.T) {
16
	tests := []struct {
17
		name  string
18
		value interface{}
19
	}{
20
		{"bool", false},
21
		{"int8", int8(0)},
22
		{"uint8", uint8(0)},
23
		{"float32", float32(0)},
24
		{"string", ""},
25
		{"bool pointer", boolValue(false)},
26
		{"int64 pointer", intValue(0)},
27
		{"uint64 pointer", uintValue(0)},
28
		{"float64 pointer", floatValue(0)},
29
		{"string pointer", stringValue("")},
30
		{"bool nil", nilBool},
31
		{"int64 nil", nilInt},
32
		{"uint64 nil", nilUint},
33
		{"float64 nil", nilFloat},
34
		{"string nil", nilString},
35
		{"time nil", nilTime},
36
		{"empty time", emptyTime},
37
		{"empty array", emptyArray},
38
		{"empty slice", emptySlice},
39
		{"empty map", emptyMap},
40
		{"empty array pointer", &emptyArray},
41
		{"empty slice pointer", &emptySlice},
42
		{"empty map pointer", &emptyMap},
43
		{"empty time pointer", &emptyTime},
44
	}
45
	for _, test := range tests {
46
		t.Run(test.name, func(t *testing.T) {
47
			err := validator.ValidateValue(test.value, validation.PropertyName("property"), it.IsNotBlank())
48
49
			validationtest.AssertIsViolationList(t, err, func(t *testing.T, violations validation.ViolationList) bool {
50
				t.Helper()
51
				if assert.Len(t, violations, 1) {
52
					assertHasOneViolation(code.NotBlank, message.NotBlank, "property")(t, err)
53
				}
54
				return true
55
			})
56
		})
57
	}
58
}
59