1- package model
1+ package validator
22
33import (
44 "testing"
55
6+ "github.com/siherrmann/validator/model"
67 "github.com/stretchr/testify/assert"
78)
89
@@ -14,7 +15,7 @@ func TestGetValidationsFromStruct(t *testing.T) {
1415 tests := []struct {
1516 name string
1617 args args
17- expected []Validation
18+ expected []model. Validation
1819 expectedError bool
1920 }{
2021 {
@@ -24,11 +25,11 @@ func TestGetValidationsFromStruct(t *testing.T) {
2425 Field1 string `vld:"equ1, gr1min1"`
2526 Field2 int `vld:"min2, gr1min1"`
2627 }{},
27- tagType : VLD ,
28+ tagType : model . VLD ,
2829 },
29- expected : []Validation {
30- {Key : "Field1" , Type : String , Requirement : "equ1" , Groups : []* Group {{Name : "gr1" , ConditionType : "min" , ConditionValue : "1" }}},
31- {Key : "Field2" , Type : Int , Requirement : "min2" , Groups : []* Group {{Name : "gr1" , ConditionType : "min" , ConditionValue : "1" }}},
30+ expected : []model. Validation {
31+ {Key : "Field1" , Type : model . String , Requirement : "equ1" , Groups : []* model. Group {{Name : "gr1" , ConditionType : "min" , ConditionValue : "1" }}},
32+ {Key : "Field2" , Type : model . Int , Requirement : "min2" , Groups : []* model. Group {{Name : "gr1" , ConditionType : "min" , ConditionValue : "1" }}},
3233 },
3334 expectedError : false ,
3435 },
@@ -41,9 +42,9 @@ func TestGetValidationsFromStruct(t *testing.T) {
4142 }{},
4243 tagType : "upd" ,
4344 },
44- expected : []Validation {
45- {Key : "Field1" , Type : String , Requirement : "equ1" },
46- {Key : "Field2" , Type : Int , Requirement : "min2" },
45+ expected : []model. Validation {
46+ {Key : "Field1" , Type : model . String , Requirement : "equ1" },
47+ {Key : "Field2" , Type : model . Int , Requirement : "min2" },
4748 },
4849 expectedError : false ,
4950 },
@@ -54,11 +55,11 @@ func TestGetValidationsFromStruct(t *testing.T) {
5455 Field1 string `json:"field1" vld:"equ1"`
5556 Field2 int `json:"field2" vld:"min2"`
5657 }{},
57- tagType : VLD ,
58+ tagType : model . VLD ,
5859 },
59- expected : []Validation {
60- {Key : "field1" , Type : String , Requirement : "equ1" },
61- {Key : "field2" , Type : Int , Requirement : "min2" },
60+ expected : []model. Validation {
61+ {Key : "field1" , Type : model . String , Requirement : "equ1" },
62+ {Key : "field2" , Type : model . Int , Requirement : "min2" },
6263 },
6364 expectedError : false ,
6465 },
@@ -70,11 +71,11 @@ func TestGetValidationsFromStruct(t *testing.T) {
7071 Name string `json:"name" vld:"equ1"`
7172 } `json:"field1" vld:"-"`
7273 }{},
73- tagType : VLD ,
74+ tagType : model . VLD ,
7475 },
75- expected : []Validation {
76- {Key : "field1" , Type : Struct , Requirement : "-" , InnerValidation : []Validation {
77- {Key : "name" , Type : String , Requirement : "equ1" },
76+ expected : []model. Validation {
77+ {Key : "field1" , Type : model . Struct , Requirement : "-" , InnerValidation : []model. Validation {
78+ {Key : "name" , Type : model . String , Requirement : "equ1" },
7879 }},
7980 },
8081 expectedError : false ,
@@ -87,28 +88,15 @@ func TestGetValidationsFromStruct(t *testing.T) {
8788 Name string `json:"name" vld:"equ1"`
8889 } `json:"field1" vld:"min1"`
8990 }{},
90- tagType : VLD ,
91+ tagType : model . VLD ,
9192 },
92- expected : []Validation {
93- {Key : "field1" , Type : Array , Requirement : "min1" , InnerValidation : []Validation {
94- {Key : "name" , Type : String , Requirement : "equ1" },
93+ expected : []model. Validation {
94+ {Key : "field1" , Type : model . Array , Requirement : "min1" , InnerValidation : []model. Validation {
95+ {Key : "name" , Type : model . String , Requirement : "equ1" },
9596 }},
9697 },
9798 expectedError : false ,
9899 },
99- {
100- name : "Valid struct with invalid struct validation" ,
101- args : args {
102- input : & struct {
103- Field1 []struct {
104- Name string `json:"name" vld:"equ"`
105- } `json:"field1" vld:"min1"`
106- }{},
107- tagType : VLD ,
108- },
109- expected : []Validation {},
110- expectedError : true ,
111- },
112100 {
113101 name : "Valid struct with invalid inner group" ,
114102 args : args {
@@ -117,31 +105,32 @@ func TestGetValidationsFromStruct(t *testing.T) {
117105 Name string `json:"name" vld:"equ1, gr"`
118106 } `json:"field1" vld:"min1"`
119107 }{},
120- tagType : VLD ,
108+ tagType : model . VLD ,
121109 },
122- expected : []Validation {},
110+ expected : []model. Validation {},
123111 expectedError : true ,
124112 },
125113 {
126- name : "Valid struct with invalid inner struct validation " ,
114+ name : "Valid struct with valid ignored field " ,
127115 args : args {
128116 input : & struct {
129- Field1 struct {
130- Name string `json:"name" vld:"equ"`
131- } `json:"field1" vld:"-"`
117+ Name string `json:"name"`
118+ Field1 string `json:"field1" vld:"-"`
132119 }{},
133- tagType : VLD ,
120+ tagType : model . VLD ,
134121 },
135- expected : []Validation {},
136- expectedError : true ,
122+ expected : []model.Validation {
123+ {Key : "field1" , Type : model .String , Requirement : "-" },
124+ },
125+ expectedError : false ,
137126 },
138127 {
139128 name : "Empty struct" ,
140129 args : args {
141130 input : & struct {}{},
142- tagType : VLD ,
131+ tagType : model . VLD ,
143132 },
144- expected : []Validation {},
133+ expected : []model. Validation {},
145134 expectedError : false ,
146135 },
147136 {
@@ -150,18 +139,18 @@ func TestGetValidationsFromStruct(t *testing.T) {
150139 input : & struct {
151140 Field1 string `vld:"equ1, gr"`
152141 }{},
153- tagType : VLD ,
142+ tagType : model . VLD ,
154143 },
155- expected : []Validation {},
144+ expected : []model. Validation {},
156145 expectedError : true ,
157146 },
158147 {
159148 name : "Invalid struct type" ,
160149 args : args {
161150 input : struct {}{},
162- tagType : VLD ,
151+ tagType : model . VLD ,
163152 },
164- expected : []Validation {},
153+ expected : []model. Validation {},
165154 expectedError : true ,
166155 },
167156 }
0 commit comments