2015-05-05 02:04:14 +08:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2015-05-08 03:10:48 +08:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2015-05-05 02:04:14 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/config/parse"
|
2015-05-08 03:10:48 +08:00
|
|
|
"github.com/mholt/caddy/middleware"
|
2015-05-05 02:04:14 +08:00
|
|
|
"github.com/mholt/caddy/server"
|
|
|
|
)
|
|
|
|
|
2015-06-20 21:59:33 +08:00
|
|
|
// NewTestController creates a new *Controller for
|
2015-05-05 02:04:14 +08:00
|
|
|
// the input specified, with a filename of "Testfile"
|
2015-06-20 21:59:33 +08:00
|
|
|
func NewTestController(input string) *Controller {
|
2015-05-06 12:53:14 +08:00
|
|
|
return &Controller{
|
2015-05-05 02:04:14 +08:00
|
|
|
Config: &server.Config{},
|
|
|
|
Dispenser: parse.NewDispenser("Testfile", strings.NewReader(input)),
|
|
|
|
}
|
|
|
|
}
|
2015-05-08 03:10:48 +08:00
|
|
|
|
2015-06-20 21:59:33 +08:00
|
|
|
// EmptyNext is a no-op function that can be passed into
|
2015-05-08 03:10:48 +08:00
|
|
|
// middleware.Middleware functions so that the assignment
|
|
|
|
// to the Next field of the Handler can be tested.
|
2015-06-20 21:59:33 +08:00
|
|
|
var EmptyNext = middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
2015-05-08 03:10:48 +08:00
|
|
|
return 0, nil
|
|
|
|
})
|
|
|
|
|
2015-06-20 21:59:33 +08:00
|
|
|
// SameNext does a pointer comparison between next1 and next2.
|
|
|
|
func SameNext(next1, next2 middleware.Handler) bool {
|
2015-05-08 03:10:48 +08:00
|
|
|
return fmt.Sprintf("%p", next1) == fmt.Sprintf("%p", next2)
|
|
|
|
}
|