about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-09 04:21:03 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-09 04:21:03 -0400
commitc0507308950bf7db65d1f6ee79ce9f67b61cbe0e (patch)
tree09184268fa8872fe403398142fbce2b78cab9907
parent7410b8cd74d0f702b087577b1793bcf541ac8371 (diff)
downloadgetwtxt-c0507308950bf7db65d1f6ee79ce9f67b61cbe0e.tar.gz
explicit init of static assets and test template init were removed: redundant
-rw-r--r--svc/cache.go27
-rw-r--r--svc/conf_test.go1
-rw-r--r--svc/handlers_test.go1
-rw-r--r--svc/init.go1
-rw-r--r--svc/init_test.go12
5 files changed, 5 insertions, 37 deletions
diff --git a/svc/cache.go b/svc/cache.go
index e2078d7..20c3953 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -33,33 +33,6 @@ func initTemplates() *template.Template {
 	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
 }
 
-func initAssets() *staticAssets {
-	confObj.Mu.RLock()
-	defer confObj.Mu.RUnlock()
-
-	css, err := os.Open(confObj.AssetsDir + "/style.css")
-	errLog("", err)
-	cssStat, err := css.Stat()
-	errLog("", err)
-	cssData, err := ioutil.ReadAll(css)
-	errLog("", err)
-
-	indStat, err := os.Stat(confObj.AssetsDir + "/tmpl/index.html")
-	errLog("", err)
-
-	var b []byte
-	buf := bytes.NewBuffer(b)
-	errLog("", tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance))
-
-	return &staticAssets{
-		mu:       sync.RWMutex{},
-		index:    buf.Bytes(),
-		indexMod: indStat.ModTime(),
-		css:      cssData,
-		cssMod:   cssStat.ModTime(),
-	}
-}
-
 func cacheTimer() bool {
 	confObj.Mu.RLock()
 	answer := time.Since(confObj.LastCache) > confObj.CacheInterval
diff --git a/svc/conf_test.go b/svc/conf_test.go
index 37e64a6..5956fa1 100644
--- a/svc/conf_test.go
+++ b/svc/conf_test.go
@@ -19,4 +19,5 @@ func Test_initConfig(t *testing.T) {
 			}
 		}
 	})
+	testConfig()
 }
diff --git a/svc/handlers_test.go b/svc/handlers_test.go
index 7f2e7d7..36c795a 100644
--- a/svc/handlers_test.go
+++ b/svc/handlers_test.go
@@ -15,6 +15,7 @@ import (
 // they'll need more than a barebones test environment to
 // get any real information. The HTTP responses are being
 // tested by me by hand, mostly.
+
 func Test_indexHandler(t *testing.T) {
 	initTestConf()
 	t.Run("indexHandler", func(t *testing.T) {
diff --git a/svc/init.go b/svc/init.go
index d585bfa..e9c64af 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -67,7 +67,6 @@ func initSvc() {
 	initDatabase()
 	go cacheAndPush()
 	tmpls = initTemplates()
-	staticCache = initAssets()
 	watchForInterrupt()
 	pingAssets()
 }
diff --git a/svc/init_test.go b/svc/init_test.go
index 8fd8e95..a9fe624 100644
--- a/svc/init_test.go
+++ b/svc/init_test.go
@@ -2,7 +2,6 @@ package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
 	"fmt"
-	"html/template"
 	"log"
 	"os"
 	"strings"
@@ -20,16 +19,15 @@ var (
 
 func initTestConf() {
 	initTestOnce.Do(func() {
+		logToNull()
 
 		testConfig()
-		tmpls = testTemplates()
-		staticCache = initAssets()
+		tmpls = initTemplates()
+		pingAssets()
 
 		confObj.Mu.RLock()
 		defer confObj.Mu.RUnlock()
 		testport = fmt.Sprintf(":%v", confObj.Port)
-
-		logToNull()
 	})
 }
 
@@ -47,10 +45,6 @@ func logToNull() {
 	log.SetOutput(hush)
 }
 
-func testTemplates() *template.Template {
-	return template.Must(template.ParseFiles("../assets/tmpl/index.html"))
-}
-
 func testConfig() {
 
 	viper.SetConfigName("getwtxt")