Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
vellum
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paweł J. Wal
vellum
Commits
64342c75
Verified
Commit
64342c75
authored
1 month ago
by
Paweł J. Wal
Browse files
Options
Downloads
Patches
Plain Diff
simple validator test
parent
e89c41d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!45
Resolve "Commons tests"
Pipeline
#502
passed
1 month ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
commons/validator_test.go
+75
-0
75 additions, 0 deletions
commons/validator_test.go
with
75 additions
and
0 deletions
commons/validator_test.go
0 → 100644
+
75
−
0
View file @
64342c75
// SPDX-FileCopyrightText: © 2025 Paweł J. Wal <p@steamshard.net>
//
// SPDX-License-Identifier: AGPL-3.0-only
package
commons_test
import
(
"testing"
"github.com/stretchr/testify/suite"
"kita.gawa.moe/paweljw/vellum/commons"
)
type
testForm
struct
{
Name
string
`validate:"required,min=3"`
}
type
ValidatorTestSuite
struct
{
suite
.
Suite
sut
*
commons
.
Validator
}
func
(
s
*
ValidatorTestSuite
)
SetupTest
()
{
s
.
sut
=
commons
.
NewValidator
()
}
func
(
s
*
ValidatorTestSuite
)
TestValidateWithValidData
()
{
form
:=
testForm
{
Name
:
"Test Name"
,
}
result
:=
s
.
sut
.
Validate
(
form
)
s
.
True
(
result
)
s
.
Nil
(
s
.
sut
.
Error
)
}
func
(
s
*
ValidatorTestSuite
)
TestValidateWithInvalidData
()
{
form
:=
testForm
{
Name
:
"Te"
,
// Too short, minimum 3 characters
}
result
:=
s
.
sut
.
Validate
(
form
)
s
.
False
(
result
)
s
.
NotNil
(
s
.
sut
.
Error
)
}
func
(
s
*
ValidatorTestSuite
)
TestMessagesWithValidData
()
{
form
:=
testForm
{
Name
:
"Test Name"
,
}
_
=
s
.
sut
.
Validate
(
form
)
messages
:=
s
.
sut
.
Messages
(
"Name"
)
s
.
Equal
(
""
,
messages
)
}
func
(
s
*
ValidatorTestSuite
)
TestMessagesWithInvalidData
()
{
form
:=
testForm
{
Name
:
"Te"
,
// Too short, minimum 3 characters
}
_
=
s
.
sut
.
Validate
(
form
)
messages
:=
s
.
sut
.
Messages
(
"Name"
)
s
.
Equal
(
"Name must be at least 3 characters in length"
,
messages
)
}
func
TestValidatorTestSuite
(
t
*
testing
.
T
)
{
suite
.
Run
(
t
,
new
(
ValidatorTestSuite
))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment