summary refs log tree commit diff stats
path: root/svc/init_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'svc/init_test.go')
-rw-r--r--svc/init_test.go50
1 files changed, 18 insertions, 32 deletions
diff --git a/svc/init_test.go b/svc/init_test.go
index 9c99a3b..cac2fe6 100644
--- a/svc/init_test.go
+++ b/svc/init_test.go
@@ -9,23 +9,35 @@ import (
 	"sync"
 	"time"
 
-	"github.com/fsnotify/fsnotify"
 	"github.com/spf13/viper"
 )
 
-var testport = fmt.Sprintf(":%v", confObj.Port)
-var hasInit = false
-
-var initTestOnce sync.Once
+var (
+	testport     string
+	initTestOnce sync.Once
+	initDBOnce   sync.Once
+)
 
 func initTestConf() {
 	initTestOnce.Do(func() {
+
 		testConfig()
 		tmpls = testTemplates()
+
+		confObj.Mu.RLock()
+		testport = fmt.Sprintf(":%v", confObj.Port)
+		confObj.Mu.RUnlock()
+
 		logToNull()
 	})
 }
 
+func initTestDB() {
+	initDBOnce.Do(func() {
+		initDatabase()
+	})
+}
+
 func logToNull() {
 	hush, err := os.Open("/dev/null")
 	if err != nil {
@@ -44,27 +56,12 @@ func testConfig() {
 	viper.SetConfigType("yml")
 	viper.AddConfigPath("..")
 
-	log.Printf("Loading configuration ...\n")
-	if err := viper.ReadInConfig(); err != nil {
-		log.Printf("%v\n", err.Error())
-		log.Printf("Using defaults ...\n")
-	} else {
-		viper.WatchConfig()
-		viper.OnConfigChange(func(e fsnotify.Event) {
-			log.Printf("Config file change detected. Reloading...\n")
-			rebindConfig()
-		})
-	}
-
 	viper.SetDefault("ListenPort", 9001)
-	viper.SetDefault("LogFile", "getwtxt.log")
 	viper.SetDefault("DatabasePath", "getwtxt.db")
 	viper.SetDefault("AssetsDirectory", "assets")
 	viper.SetDefault("DatabaseType", "leveldb")
-	viper.SetDefault("StdoutLogging", false)
 	viper.SetDefault("ReCacheInterval", "1h")
 	viper.SetDefault("DatabasePushInterval", "5m")
-
 	viper.SetDefault("Instance.SiteName", "getwtxt")
 	viper.SetDefault("Instance.OwnerName", "Anonymous Microblogger")
 	viper.SetDefault("Instance.Email", "nobody@knows")
@@ -74,25 +71,14 @@ func testConfig() {
 	confObj.Mu.Lock()
 
 	confObj.Port = viper.GetInt("ListenPort")
-	confObj.LogFile = viper.GetString("LogFile")
+	confObj.AssetsDir = "../" + viper.GetString("AssetsDirectory")
 
 	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
-
 	confObj.DBPath = viper.GetString("DatabasePath")
 	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
 
-	confObj.AssetsDir = "../" + viper.GetString("AssetsDirectory")
-
-	confObj.StdoutLogging = viper.GetBool("StdoutLogging")
-	if confObj.StdoutLogging {
-		log.Printf("Logging to stdout\n")
-	} else {
-		log.Printf("Logging to %v\n", confObj.LogFile)
-	}
-
 	confObj.CacheInterval = viper.GetDuration("StatusFetchInterval")
 	log.Printf("User status fetch interval: %v\n", confObj.CacheInterval)
-
 	confObj.DBInterval = viper.GetDuration("DatabasePushInterval")
 	log.Printf("Database push interval: %v\n", confObj.DBInterval)