Better handle of test files
After some thoughts, it is better to use the config from config files than default ones
Cette révision appartient à :
Parent
7a89b46c4a
révision
e116b30b40
7 fichiers modifiés avec 59 ajouts et 17 suppressions
10
cache/native/native_test.go
externe
10
cache/native/native_test.go
externe
|
@ -1,13 +1,23 @@
|
|||
package native
|
||||
|
||||
import (
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/common"
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/model"
|
||||
)
|
||||
|
||||
// run before config/parse.go:init()
|
||||
var _ = func() (_ struct{}) {
|
||||
config.ConfigPath = path.Join("..", "..", config.ConfigPath)
|
||||
config.DefaultConfigPath = path.Join("..", "..", config.DefaultConfigPath)
|
||||
config.Parse()
|
||||
return
|
||||
}()
|
||||
|
||||
// Basic test for deadlocks and race conditions
|
||||
func TestConcurrency(t *testing.T) {
|
||||
c := New(0.000001)
|
||||
|
|
|
@ -12,6 +12,13 @@ import (
|
|||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultConfigPath : path to the default config file (please do not change it)
|
||||
DefaultConfigPath = "config/default_config.yml"
|
||||
// ConfigPath : path to the user specific config file (please do not change it)
|
||||
ConfigPath = "config/config.yml"
|
||||
)
|
||||
|
||||
// Conf : Modified configuration
|
||||
var Conf *Config
|
||||
var privateConf Config
|
||||
|
@ -34,8 +41,12 @@ var allowedDBLogModes = map[string]bool{
|
|||
"silent": true,
|
||||
}
|
||||
|
||||
// Construct a new config variable
|
||||
func init() {
|
||||
Parse()
|
||||
}
|
||||
|
||||
// Parse : Parse config into a config variable
|
||||
func Parse() {
|
||||
getDefaultConfig()
|
||||
privateConf = *DefaultConfig
|
||||
Conf = &privateConf
|
||||
|
@ -43,10 +54,9 @@ func init() {
|
|||
}
|
||||
|
||||
func overrideDefaults() {
|
||||
path := "config/config.yml"
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := ioutil.ReadFile(ConfigPath)
|
||||
if err != nil {
|
||||
log.Printf("can't read file '%s'", path)
|
||||
log.Printf("can't read file '%s'", ConfigPath)
|
||||
}
|
||||
err = yaml.Unmarshal(data, &Conf)
|
||||
if err != nil {
|
||||
|
|
|
@ -12,10 +12,9 @@ var DefaultConfig *Config
|
|||
|
||||
func getDefaultConfig() *Config {
|
||||
DefaultConfig = &Config{}
|
||||
path := "config/default_config.yml"
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := ioutil.ReadFile(DefaultConfigPath)
|
||||
if err != nil {
|
||||
log.Printf("can't read file '%s'", path)
|
||||
log.Printf("can't read file '%s'", DefaultConfigPath)
|
||||
}
|
||||
err = yaml.Unmarshal(data, DefaultConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -2,12 +2,21 @@ package db
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/azhao12345/gorm"
|
||||
)
|
||||
|
||||
// run before config/parse.go:init()
|
||||
var _ = func() (_ struct{}) {
|
||||
config.ConfigPath = path.Join("..", config.ConfigPath)
|
||||
config.DefaultConfigPath = path.Join("..", config.DefaultConfigPath)
|
||||
config.Parse()
|
||||
return
|
||||
}()
|
||||
|
||||
type errorLogger struct {
|
||||
t *testing.T
|
||||
}
|
||||
|
@ -29,13 +38,6 @@ func TestGormInitSqlite(t *testing.T) {
|
|||
config.Conf.DBType = SqliteType
|
||||
config.Conf.DBParams = ":memory:?cache=shared&mode=memory"
|
||||
config.Conf.DBLogMode = "detailed"
|
||||
config.Conf.Models.CommentsTableName = "comments"
|
||||
config.Conf.Models.FilesTableName = "files"
|
||||
config.Conf.Models.NotificationsTableName = "notifications"
|
||||
config.Conf.Models.ReportsTableName = "torrent_reports"
|
||||
config.Conf.Models.TorrentsTableName = "torrents"
|
||||
config.Conf.Models.UploadsOldTableName = "user_uploads_old"
|
||||
config.Conf.Models.LastOldTorrentID = 90000
|
||||
|
||||
db, err := GormInit(config.Conf, &errorLogger{t})
|
||||
if err != nil {
|
||||
|
|
|
@ -3,11 +3,16 @@ package router
|
|||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
)
|
||||
|
||||
// run before router/init.go:init()
|
||||
var _ = func() (_ struct{}) {
|
||||
TemplateDir = path.Join("..", TemplateDir)
|
||||
config.ConfigPath = path.Join("..", config.ConfigPath)
|
||||
config.DefaultConfigPath = path.Join("..", config.DefaultConfigPath)
|
||||
config.Parse()
|
||||
return
|
||||
}()
|
||||
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
package metainfoFetcher
|
||||
|
||||
import (
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/model"
|
||||
"github.com/anacrolix/torrent"
|
||||
)
|
||||
|
||||
// run before config/parse.go:init()
|
||||
var _ = func() (_ struct{}) {
|
||||
config.ConfigPath = path.Join("..", "..", "..", config.ConfigPath)
|
||||
config.DefaultConfigPath = path.Join("..", "..", "..", config.DefaultConfigPath)
|
||||
config.Parse()
|
||||
return
|
||||
}()
|
||||
|
||||
func TestInvalidHash(t *testing.T) {
|
||||
client, err := torrent.NewClient(nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,10 +7,16 @@ import (
|
|||
"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.Parse()
|
||||
return
|
||||
}()
|
||||
|
||||
func TestInitI18n(t *testing.T) {
|
||||
conf := config.I18nConfig{}
|
||||
conf.Directory = "translations"
|
||||
conf.DefaultLanguage = "en-us"
|
||||
conf := config.Conf.I18n
|
||||
conf.Directory = path.Join("..", "..", conf.Directory)
|
||||
var retriever UserRetriever // not required during initialization
|
||||
|
||||
|
|
Référencer dans un nouveau ticket