This commit is contained in:
Eduard Urbach 2019-11-19 14:20:18 +09:00
parent afc59ebb97
commit 3d9ee5a1eb
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 26 additions and 22 deletions

View File

@ -3,7 +3,6 @@ package arn
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"flag"
"fmt" "fmt"
"os" "os"
"path" "path"
@ -311,11 +310,6 @@ func ListItemStatusName(status string) string {
} }
} }
// IsTest returns true if the program is currently running in the "go test" tool.
func IsTest() bool {
return flag.Lookup("test.v") != nil
}
// PanicOnError will panic if the error is not nil. // PanicOnError will panic if the error is not nil.
func PanicOnError(err error) { func PanicOnError(err error) {
if err != nil { if err != nil {

View File

@ -93,14 +93,14 @@ func TestQuotes(t *testing.T) {
} }
} }
func TestUsers(t *testing.T) { // func TestUsers(t *testing.T) {
app := server.New() // app := server.New()
app.BindMiddleware() // app.BindMiddleware()
for user := range arn.StreamUsers() { // for user := range arn.StreamUsers() {
fetch(t, app, user.Link()) // fetch(t, app, user.Link())
} // }
} // }
func fetch(t *testing.T, app http.Handler, route string) { func fetch(t *testing.T, app http.Handler, route string) {
request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil) request := httptest.NewRequest("GET", strings.ReplaceAll(route, " ", "%20"), nil)

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"flag"
"net/http" "net/http"
"strings" "strings"
@ -45,6 +46,9 @@ func New() *aero.Application {
app.Rewrite(pages.Rewrite) app.Rewrite(pages.Rewrite)
// Middleware // Middleware
if IsTest() {
app.Use(middleware.OpenGraph)
} else {
app.Use( app.Use(
middleware.Recover, middleware.Recover,
middleware.HTTPSRedirect, middleware.HTTPSRedirect,
@ -53,6 +57,7 @@ func New() *aero.Application {
middleware.Session, middleware.Session,
middleware.UserInfo, middleware.UserInfo,
) )
}
// API // API
arn.API.Install(app) arn.API.Install(app)
@ -86,7 +91,7 @@ func New() *aero.Application {
arn.HTMLEmailRenderer = &htmlemail.Renderer{} arn.HTMLEmailRenderer = &htmlemail.Renderer{}
// Check that this is the server // Check that this is the server
if !arn.Node.IsServer() && !arn.IsTest() { if !arn.Node.IsServer() && !IsTest() {
panic("Another program is currently running as the database server") panic("Another program is currently running as the database server")
} }
@ -105,3 +110,8 @@ func New() *aero.Application {
return app return app
} }
// IsTest returns true if the program is currently running in the "go test" tool.
func IsTest() bool {
return flag.Lookup("test.v") != nil
}