Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/utils/categories/categories_test.go
akuma06 713ab02450 Added configor as a new library (#1126)
* Added configor as a new library

Now config is a singleton. You only need to do config.Get() instead of doing config.Conf.

* Forgot godep save 🐤

* Fix accidental removal of }
2017-07-10 22:11:05 +10:00

69 lignes
1,7 Kio
Go

package categories
import (
"path"
"strings"
"testing"
"reflect"
"github.com/NyaaPantsu/nyaa/config"
)
// run before config/parse.go:init()
var _ = func() (_ struct{}) {
config.ConfigPath = path.Join("..", "..", config.ConfigPath)
config.DefaultConfigPath = path.Join("..", "..", config.DefaultConfigPath)
config.Reload()
return
}()
func TestGetCategories(t *testing.T) {
cats := make(map[string]string)
for _, v := range All() {
cats[v.ID] = v.Name
}
if len(cats) == 0 {
t.Skip("Couldn't load categories to test Categories")
}
if !reflect.DeepEqual(cats, config.Get().Torrents.CleanCategories) && !reflect.DeepEqual(cats, config.Get().Torrents.SukebeiCategories) {
t.Error("Categories doesn't correspond to the configured ones")
}
}
func TestCategoryExists(t *testing.T) {
if Exists("k") {
t.Error("Category that shouldn't exist return true")
}
}
func TestGetCategoriesSelect(t *testing.T) {
cats := GetSelect(true, false)
for _, value := range cats {
split := strings.Split(value.ID, "_")
if len(split) != 2 {
t.Errorf("The category %s doesn't have only one underscore", value.Name)
}
if split[1] != "" {
t.Errorf("The function doesn't filter out child categories, expected '', got %s", split[1])
}
}
cats = GetSelect(false, true)
for _, value := range cats {
split := strings.Split(value.ID, "_")
if len(split) != 2 {
t.Errorf("The category %s doesn't have only one underscore", value.Name)
}
if split[1] == "" {
t.Error("The function doesn't filter out parent categories, expected a string, got nothing")
}
}
cats = GetSelect(true, true)
if len(cats) != len(All()) {
t.Errorf("Same amount of categories isn't return when no filter applied")
}
}