mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
caddytest: internalize init config into '.go' file (#5230)
This commit is contained in:
parent
d4a7d89f56
commit
fef9cb3e05
2 changed files with 20 additions and 6 deletions
|
@ -114,7 +114,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := validateTestPrerequisites()
|
err := validateTestPrerequisites(tc.t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tc.t.Skipf("skipping tests as failed integration prerequisites. %s", err)
|
tc.t.Skipf("skipping tests as failed integration prerequisites. %s", err)
|
||||||
return nil
|
return nil
|
||||||
|
@ -224,9 +224,14 @@ func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error
|
||||||
return errors.New("EnsureConfigRunning: POSTed configuration isn't active")
|
return errors.New("EnsureConfigRunning: POSTed configuration isn't active")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const initConfig = `{
|
||||||
|
admin localhost:2999
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
// validateTestPrerequisites ensures the certificates are available in the
|
// validateTestPrerequisites ensures the certificates are available in the
|
||||||
// designated path and Caddy sub-process is running.
|
// designated path and Caddy sub-process is running.
|
||||||
func validateTestPrerequisites() error {
|
func validateTestPrerequisites(t *testing.T) error {
|
||||||
|
|
||||||
// check certificates are found
|
// check certificates are found
|
||||||
for _, certName := range Default.Certifcates {
|
for _, certName := range Default.Certifcates {
|
||||||
|
@ -236,8 +241,20 @@ func validateTestPrerequisites() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if isCaddyAdminRunning() != nil {
|
if isCaddyAdminRunning() != nil {
|
||||||
|
// setup the init config file, and set the cleanup afterwards
|
||||||
|
f, err := os.CreateTemp("", "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.Cleanup(func() {
|
||||||
|
os.Remove(f.Name())
|
||||||
|
})
|
||||||
|
if _, err := f.WriteString(initConfig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// start inprocess caddy server
|
// start inprocess caddy server
|
||||||
os.Args = []string{"caddy", "run", "--config", "./test.init.config", "--adapter", "caddyfile"}
|
os.Args = []string{"caddy", "run", "--config", f.Name(), "--adapter", "caddyfile"}
|
||||||
go func() {
|
go func() {
|
||||||
caddycmd.Main()
|
caddycmd.Main()
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
admin localhost:2999
|
|
||||||
}
|
|
Loading…
Reference in a new issue