Browse Source

Application is now an interface.

chi-radix-port
Benjamin Shelton 5 months ago
parent
commit
af5e1e38fa
21 changed files with 46 additions and 46 deletions
  1. +3
    -3
      extension.go
  2. +1
    -1
      extension/csrf.go
  3. +1
    -1
      middleware/mangler_test.go
  4. +2
    -2
      router.go
  5. +9
    -9
      tests/authentication_test.go
  6. +1
    -1
      tests/broken_requests_test.go
  7. +1
    -1
      tests/configuration_test.go
  8. +2
    -2
      tests/custom_base_route_test.go
  9. +1
    -1
      tests/hostname_test.go
  10. +2
    -2
      tests/index_endpoint_test.go
  11. +1
    -1
      tests/method_endpoint_test.go
  12. +1
    -1
      tests/method_path_override_test.go
  13. +3
    -3
      tests/middleware_test.go
  14. +1
    -1
      tests/params_test.go
  15. +6
    -6
      tests/rebind_test.go
  16. +2
    -2
      tests/redirection_test.go
  17. +1
    -1
      tests/reserved_names_test.go
  18. +1
    -1
      tests/return_types_test.go
  19. +2
    -2
      tests/routergroup_test.go
  20. +3
    -3
      tests/server.go
  21. +2
    -2
      tests/websocket_test.go

+ 3
- 3
extension.go View File

@@ -24,7 +24,7 @@ type Extension interface {
// for extensions that have dependencies on other extensions, this is called
// after the dependency has been loaded. Circular dependencies will result
// in a panic.
Init(app *Application)
Init(app Application)
}

type MiddlewareExtension interface {
@@ -54,12 +54,12 @@ type ExtensionManager struct {
extensions map[string]Extension
provides map[string]Extension
depends map[string][]Extension
app *Application
app Application

sync.RWMutex
}

func NewExtensionManager(app *Application) *ExtensionManager {
func NewExtensionManager(app Application) *ExtensionManager {
return &ExtensionManager{
extensions: make(map[string]Extension),
provides: make(map[string]Extension),


+ 1
- 1
extension/csrf.go View File

@@ -462,7 +462,7 @@ func (c *CSRF) Requires() []string {
return []string{}
}

func (c *CSRF) Init(server *capstan.Application) {
func (c *CSRF) Init(server capstan.Application) {
c.hostname = server.Config().Hostname
server.Router().BeforeResponseFunc(c.beforeResponse)
server.Dependencies().Register(c.options.InjectedName, c)


+ 1
- 1
middleware/mangler_test.go View File

@@ -25,7 +25,7 @@ func (c *MethodManglerController) Post(ctx capstan.Context) error {
}

func Test_MangleMethod(t *testing.T) {
server := tests.NewServer(func(app *capstan.Application) {
server := tests.NewServer(func(app capstan.Application) {
app.Bind(&MethodManglerController{
capstan.BaseController{
Path: "/mangle",


+ 2
- 2
router.go View File

@@ -53,7 +53,7 @@ type Router struct {
// Capstan server reference which contains most high-order things not
// involving direct management of routes and communication, like
// configuration.
app *Application
app Application

// The router basePath is used to mount the route at a location other than
// "/". If unspecified, this will default to the root path ("/").
@@ -181,7 +181,7 @@ type Router struct {
sync.RWMutex
}

func NewRouter(app *Application) *Router {
func NewRouter(app Application) *Router {
router := NewEmptyRouter()
router.app = app
router.mux = chi.NewRouter()


+ 9
- 9
tests/authentication_test.go View File

@@ -257,7 +257,7 @@ func (c *TokenAuthenticationController) Post(ctx capstan.Context) error {
}

func Test_PlainTextAuth(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
authenticator := &auth.Authenticator{
Config: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -283,7 +283,7 @@ func Test_PlainTextAuth(t *testing.T) {
}

func Test_DefaultsAuth(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -314,7 +314,7 @@ func Test_DefaultsAuth(t *testing.T) {
}

func Test_TokenAuth(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -351,7 +351,7 @@ func Test_TokenAuth(t *testing.T) {
}

func Test_ChainLoadingAuth(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -391,7 +391,7 @@ func Test_ChainLoadingAuth(t *testing.T) {
}

func Test_OnCookieDefaultsAuth(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -430,7 +430,7 @@ func Test_OnCookieDefaultsAuth(t *testing.T) {
}

func Test_AuthFreshnessGuarantee(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -548,7 +548,7 @@ func Test_AuthFreshnessGuarantee(t *testing.T) {
}

func Test_AuthMetadata(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -608,7 +608,7 @@ func Test_AuthMetadata(t *testing.T) {
}

func Test_AuthRememberCookie(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{
@@ -676,7 +676,7 @@ func Test_AuthRememberCookie(t *testing.T) {
}

func Test_AuthRememberCookieTimeout(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
conf := &config.ServerConfig{
AuthenticationConfig: &config.AuthenticationConfig{
CookieOptions: &http.Cookie{


+ 1
- 1
tests/broken_requests_test.go View File

@@ -42,7 +42,7 @@ func (c *BreakMeController) Post(ctx capstan.Context) error {
}

func Test_InvalidJSONContentType(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&BreakMeController{
capstan.BaseController{
Path: "/break-me",


+ 1
- 1
tests/configuration_test.go View File

@@ -35,7 +35,7 @@ func Test_ConfigurationProperties_BasePath(t *testing.T) {
config := NewServerConfig(&capstan.ServerConfig{
BasePath: "/root",
})
server := config(func(app *capstan.Application) {
server := config(func(app capstan.Application) {
app.Bind(&ConfigurationController{
capstan.BaseController{
Path: "/config",


+ 2
- 2
tests/custom_base_route_test.go View File

@@ -12,8 +12,8 @@ import (
"net/http"
"testing"

"git.destrealm.org/go/errors"
"git.destrealm.org/go/capstan"
"git.destrealm.org/go/errors"
"git.destrealm.org/go/please"
)

@@ -92,7 +92,7 @@ func (c *CustomBaseRouteController) GetCustomBaseRouteAbuse7SS(ctx capstan.Conte
}

func Test_CustomBaseRoutes(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&CustomBaseRouteController{
capstan.BaseController{
Path: "/custom-base-route",


+ 1
- 1
tests/hostname_test.go View File

@@ -16,7 +16,7 @@ func Test_Hostname(t *testing.T) {
Hostname: "test.example.com",
EnforceHostname: true,
})
server := setup(func(app *capstan.Application) {
server := setup(func(app capstan.Application) {
app.Bind(&MethodEndpointController{
capstan.BaseController{
Path: "/methods",


+ 2
- 2
tests/index_endpoint_test.go View File

@@ -34,7 +34,7 @@ func (c *IndexController) Get(ctx capstan.Context) error {
}

func Test_IndexController(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&IndexController{
capstan.BaseController{
Name: "index",
@@ -142,7 +142,7 @@ func Test_IndexController(t *testing.T) {
}

func Test_IndexAtRootController(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&IndexController{
capstan.BaseController{
Name: "index-sub-index",


+ 1
- 1
tests/method_endpoint_test.go View File

@@ -69,7 +69,7 @@ func (m *MethodEndpointController) Head(ctx capstan.Context) error {
// - Trace
// - Connect
func Test_MethodEndpoints(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&MethodEndpointController{
capstan.BaseController{
Path: "/methods",


+ 1
- 1
tests/method_path_override_test.go View File

@@ -55,7 +55,7 @@ func (c *MethodOverrideController) Head(ctx capstan.Context) error {
}

func Test_MethodOverride(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&MethodOverrideController{
capstan.BaseController{
Path: "/method-override",


+ 3
- 3
tests/middleware_test.go View File

@@ -58,7 +58,7 @@ func Test_MiddlewareController(t *testing.T) {
values["/middleware"] = struct{ value string }{"controller attachment"}
values["/no-middleware"] = struct{ value string }{""}

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&MiddlewareController{
capstan.BaseController{
Path: "/middleware",
@@ -105,7 +105,7 @@ func Test_MiddlewareGlobal(t *testing.T) {
values["/middleware"] = struct{ value string }{"global attachment"}
values["/controller-middleware"] = struct{ value string }{"controller middleware"}

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.SetMiddleware(testMiddleware("global attachment"))

app.Bind(&MiddlewareController{
@@ -153,7 +153,7 @@ func Test_MiddlewareRouterGroup(t *testing.T) {
values := make(map[string]struct{ value string })
values["/middleware"] = struct{ value string }{"routergroup attachment"}

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.BindGroup("/").Name("").Add(func(router *capstan.Router) {
router.Middleware(testMiddleware("routergroup attachment"))



+ 1
- 1
tests/params_test.go View File

@@ -28,7 +28,7 @@ func (c *ParamsController) Get(ctx capstan.Context) error {
}

func Test_ParameterizedRedirects(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&ParamsController{
capstan.BaseController{
Path: "/params/<from:string>!",


+ 6
- 6
tests/rebind_test.go View File

@@ -13,7 +13,7 @@ import (

type ReplacePathController struct {
capstan.BaseController
App *capstan.Application `inject:""`
App capstan.Application `inject:"app"`
}

func (c *ReplacePathController) Get(ctx capstan.Context) error {
@@ -28,7 +28,7 @@ func (c *ReplacePathController) Get(ctx capstan.Context) error {

type UnmountPathController struct {
capstan.BaseController
App *capstan.Application `inject:""`
App capstan.Application `inject:"app"`
}

func (c *UnmountPathController) Get(ctx capstan.Context) error {
@@ -44,7 +44,7 @@ func (c *UnmountPathController) Get(ctx capstan.Context) error {
// Test_ReplacePath rebinds the controller path /rebind to /rebound and
// validates that the path replacement has taken effect.
func Test_ReplacePath(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&ReplacePathController{
BaseController: capstan.BaseController{
Path: "/rebind",
@@ -91,7 +91,7 @@ func Test_ReplacePath(t *testing.T) {
}

func Test_UnmountPath(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&UnmountPathController{
BaseController: capstan.BaseController{
Path: "/unmount",
@@ -130,7 +130,7 @@ func Test_UnmountPath(t *testing.T) {
// subrouters. This replaces the root path assigned to a RouterGroup, leaving
// the base paths untouched, and validates the replacement.
func Test_ReplacePathSubrouter(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.BindGroup("/rebind").Name("").Add(func(router *capstan.Router) {
router.Bind(&ReplacePathController{
BaseController: capstan.BaseController{
@@ -179,7 +179,7 @@ func Test_ReplacePathSubrouter(t *testing.T) {
}

func Test_UnmountPathSubrouter(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.BindGroup("/unmount").Name("").Add(func(router *capstan.Router) {
router.Bind(&UnmountPathController{
BaseController: capstan.BaseController{


+ 2
- 2
tests/redirection_test.go View File

@@ -23,9 +23,9 @@ import (
"strings"
"testing"

"git.destrealm.org/go/errors"
"git.destrealm.org/go/capstan"
"git.destrealm.org/go/capstan/status"
"git.destrealm.org/go/errors"
"git.destrealm.org/go/please"
)

@@ -52,7 +52,7 @@ func (c *InternalRedirectController) Get(ctx capstan.Context) error {
}

func Test_Redirects(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {

app.Bind(&ExternalRedirectController{
capstan.BaseController{


+ 1
- 1
tests/reserved_names_test.go View File

@@ -46,7 +46,7 @@ func (c *ReservedController) Reserved2() bool {
}

func Test_ReservedNamed(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Router().ReservedFunctions("ReservedName", "Reserved")

app.Bind(&ReservedController{


+ 1
- 1
tests/return_types_test.go View File

@@ -18,7 +18,7 @@ import (
)

func Test_ReturnTypes(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {

app.Bind(&ReturnTypesController{
capstan.BaseController{


+ 2
- 2
tests/routergroup_test.go View File

@@ -40,7 +40,7 @@ func Test_RouterGroup(t *testing.T) {
Body string
}{200, "group3"}

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.BindGroup("/groups").Name("").Add(func(router *capstan.Router) {
router.Bind(&RouterGroupController{
BaseController: capstan.BaseController{
@@ -108,7 +108,7 @@ func Test_MultiRouterGroup(t *testing.T) {
Body string
}{200, "group3"}

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.BindGroup("/group1").Name("").Add(func(router *capstan.Router) {
router.Bind(&RouterGroupController{
BaseController: capstan.BaseController{


+ 3
- 3
tests/server.go View File

@@ -17,8 +17,8 @@ type ReturnTypesController struct {
capstan.BaseController
}

func NewServerConfig(conf *capstan.ServerConfig) func(func(*capstan.Application)) *httptest.Server {
return func(bind func(*capstan.Application)) *httptest.Server {
func NewServerConfig(conf *capstan.ServerConfig) func(func(capstan.Application)) *httptest.Server {
return func(bind func(capstan.Application)) *httptest.Server {
if conf.Session == nil {
conf.Session = &capstan.SessionConfig{
Backend: config.SessionCookieBackend,
@@ -46,7 +46,7 @@ func NewServerConfig(conf *capstan.ServerConfig) func(func(*capstan.Application)
}
}

func NewServer(bind func(*capstan.Application)) *httptest.Server {
func NewServer(bind func(capstan.Application)) *httptest.Server {
app := capstan.New(&capstan.ServerConfig{
Session: &capstan.SessionConfig{
Backend: config.SessionCookieBackend,


+ 2
- 2
tests/websocket_test.go View File

@@ -56,7 +56,7 @@ func Test_WebSocketGetBinding(t *testing.T) {
}
}()

server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&WebSocketController{
capstan.BaseController{
Path: "/websocket",
@@ -76,7 +76,7 @@ func Test_WebSocketGetBinding(t *testing.T) {
}

func Test_WebSocketPath(t *testing.T) {
server := NewServer(func(app *capstan.Application) {
server := NewServer(func(app capstan.Application) {
app.Bind(&WebSocketController{
capstan.BaseController{
Path: "/websocket",


Loading…
Cancel
Save