mirror of
https://github.com/caddyserver/caddy.git
synced 2025-12-08 06:09:53 +00:00
testing: make it so caddytest launches an instance of caddy per server
This commit is contained in:
parent
c2ccf8690f
commit
b732a7999a
24 changed files with 1071 additions and 881 deletions
14
cmd/main.go
14
cmd/main.go
|
|
@ -71,7 +71,7 @@ func Main() {
|
|||
if err != nil {
|
||||
caddy.Log().Warn("failed to set GOMAXPROCS", zap.Error(err))
|
||||
}
|
||||
|
||||
rootCmd := defaultFactory.Build()
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
var exitError *exitError
|
||||
if errors.As(err, &exitError) {
|
||||
|
|
@ -81,6 +81,18 @@ func Main() {
|
|||
}
|
||||
}
|
||||
|
||||
// MainForTesting implements the main function of the caddy command, used internally for testing
|
||||
func MainForTesting(args ...string) error {
|
||||
// create a root command for testing which will not pollute the global namespace, and does not
|
||||
// call os.Exit().
|
||||
rootCmd := defaultFactory.Build()
|
||||
rootCmd.SetArgs(args)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handlePingbackConn reads from conn and ensures it matches
|
||||
// the bytes in expect, or returns an error if it doesn't.
|
||||
func handlePingbackConn(conn net.Conn, expect []byte) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue