diff options
author | Mohammed Al Sahaf <[email protected]> | 2022-12-05 21:49:41 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2022-12-05 18:49:41 +0000 |
commit | fef9cb3e05ea071cdfd9ed1a6be5c8dcabf6603e (patch) | |
tree | c5cef80c06a8cd10f9a123cd85d550434e31928b /caddytest | |
parent | d4a7d89f564234e44012a763cc28c5a3991bd98e (diff) | |
download | caddy-fef9cb3e05ea071cdfd9ed1a6be5c8dcabf6603e.tar.gz caddy-fef9cb3e05ea071cdfd9ed1a6be5c8dcabf6603e.zip |
caddytest: internalize init config into '.go' file (#5230)
Diffstat (limited to 'caddytest')
-rw-r--r-- | caddytest/caddytest.go | 23 | ||||
-rw-r--r-- | caddytest/integration/test.init.config | 3 |
2 files changed, 20 insertions, 6 deletions
diff --git a/caddytest/caddytest.go b/caddytest/caddytest.go index 868b42748..0958e6c9a 100644 --- a/caddytest/caddytest.go +++ b/caddytest/caddytest.go @@ -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 @@ -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 { @@ -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() }() diff --git a/caddytest/integration/test.init.config b/caddytest/integration/test.init.config deleted file mode 100644 index 9119ebcb6..000000000 --- a/caddytest/integration/test.init.config +++ /dev/null @@ -1,3 +0,0 @@ -{ - admin localhost:2999 -} |