mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 12:16:16 +08:00
a798e0c951
- Server types no longer need to store their own contexts; they are stored on the caddy.Instance, which means each context will be properly GC'ed when the instance is stopped. Server types should use type assertions to convert from caddy.Context to their concrete context type when they need to use it. - Pass the entire context into httpserver.GetConfig instead of only the Key field. - caddy.NewTestController now requires a server type string so it can create a controller with the proper concrete context associated with that server type. Tests still need more attention so that we can test the proper creation of startup functions, etc.
33 lines
622 B
Go
33 lines
622 B
Go
package pprof
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mholt/caddy"
|
|
)
|
|
|
|
func TestSetup(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
shouldErr bool
|
|
}{
|
|
{`pprof`, false},
|
|
{`pprof {}`, true},
|
|
{`pprof /foo`, true},
|
|
{`pprof {
|
|
a b
|
|
}`, true},
|
|
{`pprof
|
|
pprof`, true},
|
|
}
|
|
for i, test := range tests {
|
|
c := caddy.NewTestController("http", test.input)
|
|
err := setup(c)
|
|
if test.shouldErr && err == nil {
|
|
t.Errorf("Test %v: Expected error but found nil", i)
|
|
} else if !test.shouldErr && err != nil {
|
|
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
|
|
}
|
|
}
|
|
}
|