Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Add template and db tests (#291)

- The db test will run an sqlite3 database in in-memory
  mode and run the automigrations.
- The template test will check if all the templates
  that are stored in package variables (template.Must)
  compile and if ReloadTemplates works without panicking.
Cette révision appartient à :
Atvaark 2017-05-11 01:15:36 +02:00 révisé par Austin
Parent 12bb79b4f5
révision 0678d19097
4 fichiers modifiés avec 47 ajouts et 7 suppressions

24
db/gorm_test.go Fichier normal
Voir le fichier

@ -0,0 +1,24 @@
package db
import (
"testing"
"github.com/ewhal/nyaa/config"
)
func TestGormInit(t *testing.T) {
conf := config.New()
conf.DBType = "sqlite3"
conf.DBParams = ":memory:?cache=shared&mode=memory"
db, err := GormInit(conf)
if err != nil {
t.Errorf("failed to initialize database: %v", err)
return
}
err = db.Close()
if err != nil {
t.Errorf("failed to close database: %v", err)
}
}

Voir le fichier

@ -31,17 +31,17 @@ var panelIndex, panelTorrentList, panelUserList, panelCommentList, panelTorrentE
func init() { func init() {
panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html"))) panelTorrentList = template.Must(template.New("torrentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrentlist.html")))
panelTorrentList = template.Must(panelTorrentList.ParseGlob(filepath.Join("templates", "_*.html"))) panelTorrentList = template.Must(panelTorrentList.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html"))) panelUserList = template.Must(template.New("userlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/userlist.html")))
panelUserList = template.Must(panelUserList.ParseGlob(filepath.Join("templates", "_*.html"))) panelUserList = template.Must(panelUserList.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html"))) panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
panelCommentList = template.Must(panelCommentList.ParseGlob(filepath.Join("templates", "_*.html"))) panelCommentList = template.Must(panelCommentList.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html"))) panelIndex = template.Must(template.New("indexPanel").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/panelindex.html")))
panelIndex = template.Must(panelIndex.ParseGlob(filepath.Join("templates", "_*.html"))) panelIndex = template.Must(panelIndex.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
panelTorrentEd = template.Must(template.New("torrent_ed").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html"))) panelTorrentEd = template.Must(template.New("torrent_ed").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/paneltorrentedit.html")))
panelTorrentEd = template.Must(panelTorrentEd.ParseGlob(filepath.Join("templates", "_*.html"))) panelTorrentEd = template.Must(panelTorrentEd.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
panelTorrentReportList = template.Must(template.New("torrent_report").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrent_report.html"))) panelTorrentReportList = template.Must(template.New("torrent_report").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/torrent_report.html")))
panelTorrentReportList = template.Must(panelTorrentReportList.ParseGlob(filepath.Join("templates", "_*.html"))) panelTorrentReportList = template.Must(panelTorrentReportList.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
} }
func IndexModPanel(w http.ResponseWriter, r *http.Request) { func IndexModPanel(w http.ResponseWriter, r *http.Request) {

Voir le fichier

@ -86,7 +86,7 @@ func ReloadTemplates() {
} }
for _, templ := range templs { for _, templ := range templs {
t := template.Must(template.New(templ.name).Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "index.html"), filepath.Join(TemplateDir, templ.file))) t := template.Must(template.New(templ.name).Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "index.html"), filepath.Join(TemplateDir, templ.file)))
t = template.Must(t.ParseGlob(filepath.Join("templates", "_*.html"))) t = template.Must(t.ParseGlob(filepath.Join(TemplateDir, "_*.html")))
*templ.templ = t *templ.templ = t
} }

16
router/template_test.go Fichier normal
Voir le fichier

@ -0,0 +1,16 @@
package router
import (
"path"
"testing"
)
// run before router/init.go:init()
var _ = func() (_ struct{}) {
TemplateDir = path.Join("..", TemplateDir)
return
}()
func TestReloadTemplates(t *testing.T) {
ReloadTemplates()
}