mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-19 01:05:37 +03:00
Move controller_test.go into controller.go
Turns out the stuff in the test file needs to be exported so external add-ons can use them
This commit is contained in:
parent
ec676fa15e
commit
698399e61f
2 changed files with 37 additions and 32 deletions
|
@ -1,11 +1,48 @@
|
||||||
package setup
|
package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mholt/caddy/config/parse"
|
"github.com/mholt/caddy/config/parse"
|
||||||
|
"github.com/mholt/caddy/middleware"
|
||||||
"github.com/mholt/caddy/server"
|
"github.com/mholt/caddy/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Controller is given to the setup function of middlewares which
|
||||||
|
// gives them access to be able to read tokens and set config.
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
*server.Config
|
*server.Config
|
||||||
parse.Dispenser
|
parse.Dispenser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTestController creates a new *Controller for
|
||||||
|
// the input specified, with a filename of "Testfile"
|
||||||
|
//
|
||||||
|
// Used primarily for testing but needs to be exported so
|
||||||
|
// add-ons can use this as a convenience.
|
||||||
|
func NewTestController(input string) *Controller {
|
||||||
|
return &Controller{
|
||||||
|
Config: &server.Config{},
|
||||||
|
Dispenser: parse.NewDispenser("Testfile", strings.NewReader(input)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmptyNext is a no-op function that can be passed into
|
||||||
|
// middleware.Middleware functions so that the assignment
|
||||||
|
// to the Next field of the Handler can be tested.
|
||||||
|
//
|
||||||
|
// Used primarily for testing but needs to be exported so
|
||||||
|
// add-ons can use this as a convenience.
|
||||||
|
var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
return 0, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
// SameNext does a pointer comparison between next1 and next2.
|
||||||
|
//
|
||||||
|
// Used primarily for testing but needs to be exported so
|
||||||
|
// add-ons can use this as a convenience.
|
||||||
|
func SameNext(next1, next2 middleware.Handler) bool {
|
||||||
|
return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2)
|
||||||
|
}
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package setup
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/mholt/caddy/config/parse"
|
|
||||||
"github.com/mholt/caddy/middleware"
|
|
||||||
"github.com/mholt/caddy/server"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewTestController creates a new *Controller for
|
|
||||||
// the input specified, with a filename of "Testfile"
|
|
||||||
func NewTestController(input string) *Controller {
|
|
||||||
return &Controller{
|
|
||||||
Config: &server.Config{},
|
|
||||||
Dispenser: parse.NewDispenser("Testfile", strings.NewReader(input)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EmptyNext is a no-op function that can be passed into
|
|
||||||
// middleware.Middleware functions so that the assignment
|
|
||||||
// to the Next field of the Handler can be tested.
|
|
||||||
var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
|
||||||
return 0, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
// SameNext does a pointer comparison between next1 and next2.
|
|
||||||
func SameNext(next1, next2 middleware.Handler) bool {
|
|
||||||
return fmt.Sprintf("%v", next1) == fmt.Sprintf("%v", next2)
|
|
||||||
}
|
|
Loading…
Reference in a new issue