61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
|
package hw09structvalidator
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
type UserRole string
|
||
|
|
||
|
// Test the function on different structures and other types.
|
||
|
type (
|
||
|
User struct {
|
||
|
ID string `json:"id" validate:"len:36"`
|
||
|
Name string
|
||
|
Age int `validate:"min:18|max:50"`
|
||
|
Email string `validate:"regexp:^\\w+@\\w+\\.\\w+$"`
|
||
|
Role UserRole `validate:"in:admin,stuff"`
|
||
|
Phones []string `validate:"len:11"`
|
||
|
meta json.RawMessage //nolint:unused
|
||
|
}
|
||
|
|
||
|
App struct {
|
||
|
Version string `validate:"len:5"`
|
||
|
}
|
||
|
|
||
|
Token struct {
|
||
|
Header []byte
|
||
|
Payload []byte
|
||
|
Signature []byte
|
||
|
}
|
||
|
|
||
|
Response struct {
|
||
|
Code int `validate:"in:200,404,500"`
|
||
|
Body string `json:"omitempty"`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func TestValidate(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
in interface{}
|
||
|
expectedErr error
|
||
|
}{
|
||
|
{
|
||
|
// Place your code here.
|
||
|
},
|
||
|
// ...
|
||
|
// Place your code here.
|
||
|
}
|
||
|
|
||
|
for i, tt := range tests {
|
||
|
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
|
||
|
tt := tt
|
||
|
t.Parallel()
|
||
|
|
||
|
// Place your code here.
|
||
|
_ = tt
|
||
|
})
|
||
|
}
|
||
|
}
|