Skip to content

Commit

Permalink
caddytest: internalize init config into '.go' file (#5230)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammed90 authored Dec 5, 2022
1 parent d4a7d89 commit fef9cb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 20 additions & 3 deletions caddytest/caddytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
return nil
}

err := validateTestPrerequisites()
err := validateTestPrerequisites(tc.t)
if err != nil {
tc.t.Skipf("skipping tests as failed integration prerequisites. %s", err)
return nil
Expand Down Expand Up @@ -224,9 +224,14 @@ func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error
return errors.New("EnsureConfigRunning: POSTed configuration isn't active")
}

const initConfig = `{
admin localhost:2999
}
`

// validateTestPrerequisites ensures the certificates are available in the
// designated path and Caddy sub-process is running.
func validateTestPrerequisites() error {
func validateTestPrerequisites(t *testing.T) error {

// check certificates are found
for _, certName := range Default.Certifcates {
Expand All @@ -236,8 +241,20 @@ func validateTestPrerequisites() error {
}

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
os.Args = []string{"caddy", "run", "--config", "./test.init.config", "--adapter", "caddyfile"}
os.Args = []string{"caddy", "run", "--config", f.Name(), "--adapter", "caddyfile"}
go func() {
caddycmd.Main()
}()
Expand Down
3 changes: 0 additions & 3 deletions caddytest/integration/test.init.config

This file was deleted.

0 comments on commit fef9cb3

Please sign in to comment.