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 (
"encoding/json"
"errors"
"flag"
"fmt"
"os"
"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.
func PanicOnError(err error) {
if err != nil {

View File

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

View File

@ -1,6 +1,7 @@
package server
import (
"flag"
"net/http"
"strings"
@ -45,6 +46,9 @@ func New() *aero.Application {
app.Rewrite(pages.Rewrite)
// Middleware
if IsTest() {
app.Use(middleware.OpenGraph)
} else {
app.Use(
middleware.Recover,
middleware.HTTPSRedirect,
@ -53,6 +57,7 @@ func New() *aero.Application {
middleware.Session,
middleware.UserInfo,
)
}
// API
arn.API.Install(app)
@ -86,7 +91,7 @@ func New() *aero.Application {
arn.HTMLEmailRenderer = &htmlemail.Renderer{}
// 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")
}
@ -105,3 +110,8 @@ func New() *aero.Application {
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
}