Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

add validator package

Cette révision appartient à :
akuma06 2017-07-31 03:23:21 +02:00
Parent 6e5be0f7f1
révision 93a2c5b98e
4 fichiers modifiés avec 48 ajouts et 1 suppressions

Voir le fichier

@ -15,7 +15,7 @@ import (
"github.com/NyaaPantsu/nyaa/utils/log"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/NyaaPantsu/nyaa/utils/validator/tags"
"github.com/NyaaPantsu/nyaa/utils/validator/tag"
"github.com/gin-gonic/gin"
)

6
utils/validator/tag/forms.go Fichier normal
Voir le fichier

@ -0,0 +1,6 @@
package tagsValidator
type CreateForm struct {
Tag string `validate:"required" form:"tag"`
Type string `validate:"required" form:"type"`
}

Voir le fichier

@ -0,0 +1,7 @@
package tagsValidator
import "github.com/NyaaPantsu/nyaa/config"
func CheckTagType(tagType string) bool {
return config.Get().Torrents.Tags.Types.Contains(tagType)
}

Voir le fichier

@ -0,0 +1,34 @@
package tagsValidator
import (
"path"
"testing"
"github.com/NyaaPantsu/nyaa/config"
)
// run before config/parse.go:init()
var _ = func() (_ struct{}) {
config.Configpaths[1] = path.Join("..", "..", "..", config.Configpaths[1])
config.Configpaths[0] = path.Join("..", "..", "..", config.Configpaths[0])
config.Reload()
return
}()
func TestCheckTagType(t *testing.T) {
tests := []struct {
Type string
Expected bool
}{
{"", false},
{"akuma06", false},
{"quality", true},
{"anidb", false},
}
for _, test := range tests {
b := CheckTagType(test.Type)
if b != test.Expected {
t.Errorf("Error when checking tag type '%s', want '%t', got '%t'", test.Type, test.Expected, b)
}
}
}