summaryrefslogtreecommitdiff
path: root/testrig
diff options
context:
space:
mode:
Diffstat (limited to 'testrig')
-rw-r--r--testrig/processor.go2
-rw-r--r--testrig/router.go30
-rw-r--r--testrig/timelinemanager.go11
3 files changed, 31 insertions, 12 deletions
diff --git a/testrig/processor.go b/testrig/processor.go
index cc2c3605e..4f3f8ae8a 100644
--- a/testrig/processor.go
+++ b/testrig/processor.go
@@ -29,5 +29,5 @@ import (
// NewTestProcessor returns a Processor suitable for testing purposes
func NewTestProcessor(db db.DB, storage *kv.KVStore, federator federation.Federator, emailSender email.Sender, mediaManager media.Manager) processing.Processor {
- return processing.NewProcessor(NewTestTypeConverter(db), federator, NewTestOauthServer(db), mediaManager, storage, NewTestTimelineManager(db), db, emailSender)
+ return processing.NewProcessor(NewTestTypeConverter(db), federator, NewTestOauthServer(db), mediaManager, storage, db, emailSender)
}
diff --git a/testrig/router.go b/testrig/router.go
index 6842c0210..7f883cd6a 100644
--- a/testrig/router.go
+++ b/testrig/router.go
@@ -20,7 +20,14 @@ package testrig
import (
"context"
+ "fmt"
+ "os"
+ "path/filepath"
+ "runtime"
+ "github.com/gin-gonic/gin"
+ "github.com/spf13/viper"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
@@ -33,3 +40,26 @@ func NewTestRouter(db db.DB) router.Router {
}
return r
}
+
+// ConfigureTemplatesWithGin will panic on any errors related to template loading during tests
+func ConfigureTemplatesWithGin(engine *gin.Engine) {
+
+ router.LoadTemplateFunctions(engine)
+
+ // https://stackoverflow.com/questions/31873396/is-it-possible-to-get-the-current-root-of-package-structure-as-a-string-in-golan
+ _, runtimeCallerLocation, _, _ := runtime.Caller(0)
+ projectRoot, err := filepath.Abs(filepath.Join(filepath.Dir(runtimeCallerLocation), "../"))
+ if err != nil {
+ panic(err)
+ }
+
+ templateBaseDir := viper.GetString(config.Keys.WebTemplateBaseDir)
+
+ _, err = os.Stat(filepath.Join(projectRoot, templateBaseDir, "index.tmpl"))
+ if err != nil {
+ panic(fmt.Errorf("%s doesn't seem to contain the templates; index.tmpl is missing: %s", filepath.Join(projectRoot, templateBaseDir), err))
+ }
+
+ tmPath := filepath.Join(projectRoot, fmt.Sprintf("%s*", templateBaseDir))
+ engine.LoadHTMLGlob(tmPath)
+}
diff --git a/testrig/timelinemanager.go b/testrig/timelinemanager.go
deleted file mode 100644
index 4b316a52e..000000000
--- a/testrig/timelinemanager.go
+++ /dev/null
@@ -1,11 +0,0 @@
-package testrig
-
-import (
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/timeline"
-)
-
-// NewTestTimelineManager retuts a new timeline.Manager, suitable for testing, using the given db.
-func NewTestTimelineManager(db db.DB) timeline.Manager {
- return timeline.NewManager(db, NewTestTypeConverter(db))
-}