@marcel91200 / caddy Mirror · read-only / commits / fef9cb3e
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 09:15 UTC

caddytest: internalize init config into '.go' file (#5230)

Mohammed Al Sahaf committed Dec 5, 2022 at 21:49 UTC fef9cb3e05ea071cdfd9ed1a6be5c8dcabf6603e
2 files changed +20 -6
caddytest/caddytest.go
+20 -3
@@ -114,7 +114,7 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
114 return nil
115 }
116
117 - err := validateTestPrerequisites()
117 + err := validateTestPrerequisites(tc.t)
118 if err != nil {
119 tc.t.Skipf("skipping tests as failed integration prerequisites. %s", err)
120 return nil
@@ -224,9 +224,14 @@ func (tc *Tester) ensureConfigRunning(rawConfig string, configType string) error
224 return errors.New("EnsureConfigRunning: POSTed configuration isn't active")
225 }
226
227 +const initConfig = `{
228 + admin localhost:2999
229 +}
230 +`
231 +
232 // validateTestPrerequisites ensures the certificates are available in the
233 // designated path and Caddy sub-process is running.
229 -func validateTestPrerequisites() error {
234 +func validateTestPrerequisites(t *testing.T) error {
235
236 // check certificates are found
237 for _, certName := range Default.Certifcates {
@@ -236,8 +241,20 @@ func validateTestPrerequisites() error {
241 }
242
243 if isCaddyAdminRunning() != nil {
244 + // setup the init config file, and set the cleanup afterwards
245 + f, err := os.CreateTemp("", "")
246 + if err != nil {
247 + return err
248 + }
249 + t.Cleanup(func() {
250 + os.Remove(f.Name())
251 + })
252 + if _, err := f.WriteString(initConfig); err != nil {
253 + return err
254 + }
255 +
256 // start inprocess caddy server
240 - os.Args = []string{"caddy", "run", "--config", "./test.init.config", "--adapter", "caddyfile"}
257 + os.Args = []string{"caddy", "run", "--config", f.Name(), "--adapter", "caddyfile"}
258 go func() {
259 caddycmd.Main()
260 }()
caddytest/integration/test.init.config deleted
-3
@@ -1,3 +0,0 @@
1 -{
2 - admin localhost:2999
3 -}