mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-26 02:09:47 +08:00
41 lines
990 B
Go
41 lines
990 B
Go
|
package expvar
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/mholt/caddy"
|
||
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
||
|
)
|
||
|
|
||
|
func TestSetup(t *testing.T) {
|
||
|
err := setup(caddy.NewTestController(`expvar`))
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected no errors, got: %v", err)
|
||
|
}
|
||
|
mids := httpserver.GetConfig("").Middleware()
|
||
|
if len(mids) == 0 {
|
||
|
t.Fatal("Expected middleware, got 0 instead")
|
||
|
}
|
||
|
|
||
|
err = setup(caddy.NewTestController(`expvar /d/v`))
|
||
|
if err != nil {
|
||
|
t.Errorf("Expected no errors, got: %v", err)
|
||
|
}
|
||
|
mids = httpserver.GetConfig("").Middleware()
|
||
|
if len(mids) == 0 {
|
||
|
t.Fatal("Expected middleware, got 0 instead")
|
||
|
}
|
||
|
|
||
|
handler := mids[1](httpserver.EmptyNext)
|
||
|
myHandler, ok := handler.(ExpVar)
|
||
|
if !ok {
|
||
|
t.Fatalf("Expected handler to be type ExpVar, got: %#v", handler)
|
||
|
}
|
||
|
if myHandler.Resource != "/d/v" {
|
||
|
t.Errorf("Expected /d/v as expvar resource")
|
||
|
}
|
||
|
if !httpserver.SameNext(myHandler.Next, httpserver.EmptyNext) {
|
||
|
t.Error("'Next' field of handler was not set properly")
|
||
|
}
|
||
|
}
|