Skip to content

Commit 9d2f8a1

Browse files
committed
feat: cover ogrn validator
1 parent 8a9710d commit 9d2f8a1

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

validator_test.go

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,69 @@ func TestIsINNValid(t *testing.T) {
159159
func TestValidateOGRN(t *testing.T) {
160160
t.Parallel()
161161

162-
t.Run("", func(t *testing.T) {
162+
t.Run("invalid ogrn length", func(t *testing.T) {
163+
testCases := []TestCodeCase{
164+
TestCodeCase{
165+
Code: "1027700132195",
166+
Error: nil,
167+
IsValid: true,
168+
},
169+
TestCodeCase{
170+
Code: "1027739244741",
171+
Error: nil,
172+
IsValid: true,
173+
},
174+
TestCodeCase{
175+
Code: "102773924",
176+
Error: ErrInvalidOGRNLength,
177+
IsValid: false,
178+
},
179+
TestCodeCase{
180+
Code: "10277392447411231",
181+
Error: ErrInvalidOGRNLength,
182+
IsValid: false,
183+
},
184+
}
185+
for _, test := range testCases {
186+
isValid, err := IsOGRNValid(test.Code)
187+
assert.Equal(t, isValid, test.IsValid, test.Code)
188+
assert.Equal(t, true, errors.Is(test.Error, err), test.Code)
189+
}
190+
})
163191

192+
t.Run("invalid ogrn value", func(t *testing.T) {
193+
testCases := []TestCodeCase{
194+
TestCodeCase{
195+
Code: "102773??44741",
196+
Error: ErrInvalidValue,
197+
IsValid: false,
198+
},
199+
TestCodeCase{
200+
Code: "1027739244742",
201+
Error: nil,
202+
IsValid: false,
203+
},
204+
TestCodeCase{
205+
Code: "10@7739244%42",
206+
Error: ErrInvalidValue,
207+
IsValid: false,
208+
},
209+
TestCodeCase{
210+
Code: "1027700132195",
211+
Error: nil,
212+
IsValid: true,
213+
},
214+
TestCodeCase{
215+
Code: "1027739244741",
216+
Error: nil,
217+
IsValid: true,
218+
},
219+
}
220+
for _, test := range testCases {
221+
isValid, err := IsOGRNValid(test.Code)
222+
assert.Equal(t, isValid, test.IsValid, test.Code, test.IsValid)
223+
assert.Equal(t, true, errors.Is(test.Error, err), test.Code)
224+
}
164225
})
165226
}
166227

0 commit comments

Comments
 (0)