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
|
@ -1,13 +1,23 @@
|
||||||
package native
|
package native
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/common"
|
"github.com/NyaaPantsu/nyaa/common"
|
||||||
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/NyaaPantsu/nyaa/model"
|
"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
|
// Basic test for deadlocks and race conditions
|
||||||
func TestConcurrency(t *testing.T) {
|
func TestConcurrency(t *testing.T) {
|
||||||
c := New(0.000001)
|
c := New(0.000001)
|
||||||
|
|
|
@ -12,6 +12,13 @@ import (
|
||||||
yaml "gopkg.in/yaml.v2"
|
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
|
// Conf : Modified configuration
|
||||||
var Conf *Config
|
var Conf *Config
|
||||||
var privateConf Config
|
var privateConf Config
|
||||||
|
@ -34,8 +41,12 @@ var allowedDBLogModes = map[string]bool{
|
||||||
"silent": true,
|
"silent": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a new config variable
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse : Parse config into a config variable
|
||||||
|
func Parse() {
|
||||||
getDefaultConfig()
|
getDefaultConfig()
|
||||||
privateConf = *DefaultConfig
|
privateConf = *DefaultConfig
|
||||||
Conf = &privateConf
|
Conf = &privateConf
|
||||||
|
@ -43,10 +54,9 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func overrideDefaults() {
|
func overrideDefaults() {
|
||||||
path := "config/config.yml"
|
data, err := ioutil.ReadFile(ConfigPath)
|
||||||
data, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't read file '%s'", path)
|
log.Printf("can't read file '%s'", ConfigPath)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(data, &Conf)
|
err = yaml.Unmarshal(data, &Conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,10 +12,9 @@ var DefaultConfig *Config
|
||||||
|
|
||||||
func getDefaultConfig() *Config {
|
func getDefaultConfig() *Config {
|
||||||
DefaultConfig = &Config{}
|
DefaultConfig = &Config{}
|
||||||
path := "config/default_config.yml"
|
data, err := ioutil.ReadFile(DefaultConfigPath)
|
||||||
data, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't read file '%s'", path)
|
log.Printf("can't read file '%s'", DefaultConfigPath)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(data, DefaultConfig)
|
err = yaml.Unmarshal(data, DefaultConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,12 +2,21 @@ package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/azhao12345/gorm"
|
"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 {
|
type errorLogger struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
}
|
}
|
||||||
|
@ -29,13 +38,6 @@ func TestGormInitSqlite(t *testing.T) {
|
||||||
config.Conf.DBType = SqliteType
|
config.Conf.DBType = SqliteType
|
||||||
config.Conf.DBParams = ":memory:?cache=shared&mode=memory"
|
config.Conf.DBParams = ":memory:?cache=shared&mode=memory"
|
||||||
config.Conf.DBLogMode = "detailed"
|
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})
|
db, err := GormInit(config.Conf, &errorLogger{t})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -3,11 +3,16 @@ package router
|
||||||
import (
|
import (
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// run before router/init.go:init()
|
// run before router/init.go:init()
|
||||||
var _ = func() (_ struct{}) {
|
var _ = func() (_ struct{}) {
|
||||||
TemplateDir = path.Join("..", TemplateDir)
|
TemplateDir = path.Join("..", TemplateDir)
|
||||||
|
config.ConfigPath = path.Join("..", config.ConfigPath)
|
||||||
|
config.DefaultConfigPath = path.Join("..", config.DefaultConfigPath)
|
||||||
|
config.Parse()
|
||||||
return
|
return
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
package metainfoFetcher
|
package metainfoFetcher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/NyaaPantsu/nyaa/model"
|
"github.com/NyaaPantsu/nyaa/model"
|
||||||
"github.com/anacrolix/torrent"
|
"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) {
|
func TestInvalidHash(t *testing.T) {
|
||||||
client, err := torrent.NewClient(nil)
|
client, err := torrent.NewClient(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,10 +7,16 @@ import (
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"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) {
|
func TestInitI18n(t *testing.T) {
|
||||||
conf := config.I18nConfig{}
|
conf := config.Conf.I18n
|
||||||
conf.Directory = "translations"
|
|
||||||
conf.DefaultLanguage = "en-us"
|
|
||||||
conf.Directory = path.Join("..", "..", conf.Directory)
|
conf.Directory = path.Join("..", "..", conf.Directory)
|
||||||
var retriever UserRetriever // not required during initialization
|
var retriever UserRetriever // not required during initialization
|
||||||
|
|
||||||
|
|
Référencer dans un nouveau ticket