0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/config/setup/controllertest.go

33 lines
916 B
Go
Raw Normal View History

2015-05-04 13:04:14 -05:00
package setup
import (
"fmt"
"net/http"
2015-05-04 13:04:14 -05:00
"strings"
"github.com/mholt/caddy/config/parse"
"github.com/mholt/caddy/middleware"
2015-05-04 13:04:14 -05:00
"github.com/mholt/caddy/server"
)
// NewTestController creates a new *Controller for
2015-05-04 13:04:14 -05:00
// the input specified, with a filename of "Testfile"
func NewTestController(input string) *Controller {
return &Controller{
2015-05-04 13:04:14 -05:00
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("%p", next1) == fmt.Sprintf("%p", next2)
}