This commit is contained in:
parent
58e044bb36
commit
85babcbbb3
|
@ -152,6 +152,23 @@ func (k Key) GetStringSlice() []string {
|
||||||
return viper.GetStringSlice(string(k))
|
return viper.GetStringSlice(string(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timezone *time.Location
|
||||||
|
|
||||||
|
// GetTimeZone returns the time zone configured for vikunja
|
||||||
|
// It is a seperate function and not done through viper because that makes handling
|
||||||
|
// it way easier, especially when testing.
|
||||||
|
func GetTimeZone() *time.Location {
|
||||||
|
if timezone == nil {
|
||||||
|
loc, err := time.LoadLocation(ServiceTimeZone.GetString())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error parsing time zone: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
timezone = loc
|
||||||
|
}
|
||||||
|
return timezone
|
||||||
|
}
|
||||||
|
|
||||||
// Set sets a value
|
// Set sets a value
|
||||||
func (k Key) Set(i interface{}) {
|
func (k Key) Set(i interface{}) {
|
||||||
viper.Set(string(k), i)
|
viper.Set(string(k), i)
|
||||||
|
|
|
@ -72,11 +72,7 @@ func CreateDBEngine() (engine *xorm.Engine, err error) {
|
||||||
log.Fatalf("Unknown database type %s", config.DatabaseType.GetString())
|
log.Fatalf("Unknown database type %s", config.DatabaseType.GetString())
|
||||||
}
|
}
|
||||||
|
|
||||||
loc, err := time.LoadLocation(config.ServiceTimeZone.GetString())
|
engine.SetTZLocation(config.GetTimeZone())
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse timezone '%s': %s", config.ServiceTimeZone.GetString(), err)
|
|
||||||
}
|
|
||||||
engine.SetTZLocation(loc)
|
|
||||||
engine.SetMapper(core.GonicMapper{})
|
engine.SetMapper(core.GonicMapper{})
|
||||||
logger := log.NewXormLogger("")
|
logger := log.NewXormLogger("")
|
||||||
engine.SetLogger(logger)
|
engine.SetLogger(logger)
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
@ -50,11 +49,7 @@ func CreateTestEngine() (engine *xorm.Engine, err error) {
|
||||||
logger := log.NewXormLogger("DEBUG")
|
logger := log.NewXormLogger("DEBUG")
|
||||||
logger.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1")
|
logger.ShowSQL(os.Getenv("UNIT_TESTS_VERBOSE") == "1")
|
||||||
engine.SetLogger(logger)
|
engine.SetLogger(logger)
|
||||||
loc, err := time.LoadLocation(config.ServiceTimeZone.GetString())
|
engine.SetTZLocation(config.GetTimeZone())
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not parse timezone '%s': %s", config.ServiceTimeZone.GetString(), err)
|
|
||||||
}
|
|
||||||
engine.SetTZLocation(loc)
|
|
||||||
x = engine
|
x = engine
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ func InitFixtures(tablenames ...string) (err error) {
|
||||||
testfixtures.Database(x.DB().DB),
|
testfixtures.Database(x.DB().DB),
|
||||||
testfixtures.Dialect(config.DatabaseType.GetString()),
|
testfixtures.Dialect(config.DatabaseType.GetString()),
|
||||||
testfixtures.DangerousSkipTestDatabaseCheck(),
|
testfixtures.DangerousSkipTestDatabaseCheck(),
|
||||||
|
testfixtures.Location(config.GetTimeZone()),
|
||||||
testfiles,
|
testfiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,21 +26,30 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func setupTime() {
|
||||||
|
var err error
|
||||||
|
loc, err := time.LoadLocation("GMT")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error setting up time: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
testCreatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-01T15:13:12.0+00:00", loc)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error setting up time: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
testCreatedTime = testCreatedTime.In(loc)
|
||||||
|
testUpdatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-02T15:13:12.0+00:00", loc)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error setting up time: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
testUpdatedTime = testUpdatedTime.In(loc)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
var err error
|
setupTime()
|
||||||
testCreatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-01T15:13:12.0+00:00", time.Local)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error setting up time: %s", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
testCreatedTime = testCreatedTime.Local()
|
|
||||||
testUpdatedTime, err = time.ParseInLocation(time.RFC3339Nano, "2018-12-02T15:13:12.0+00:00", time.Local)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error setting up time: %s", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
testUpdatedTime = testUpdatedTime.Local()
|
|
||||||
|
|
||||||
// Set default config
|
// Set default config
|
||||||
config.InitDefaultConfig()
|
config.InitDefaultConfig()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user