()
| 160 | } |
| 161 | |
| 162 | func (t *T) ensureCanRun() { |
| 163 | if t.cfg == "" { |
| 164 | panic("tests: Run called without configuration set") |
| 165 | } |
| 166 | if t.dnsServ == nil { |
| 167 | // If there is no DNS zones set in test - start a server that will |
| 168 | // respond with NXDOMAIN to all queries to avoid accidentally leaking |
| 169 | // any DNS queries to the real world. |
| 170 | t.Log("NOTE: Explicit DNS(nil) is recommended.") |
| 171 | t.DNS(nil) |
| 172 | } |
| 173 | |
| 174 | // Setup file system, create statedir, runtimedir, write out config. |
| 175 | if t.testDir == "" { |
| 176 | testDir, err := os.MkdirTemp("", "maddy-tests-") |
| 177 | if err != nil { |
| 178 | t.Fatal("Test configuration failed:", err) |
| 179 | } |
| 180 | t.testDir = testDir |
| 181 | t.Log("using", t.testDir) |
| 182 | |
| 183 | if err := os.MkdirAll(filepath.Join(t.testDir, "statedir"), os.ModePerm); err != nil { |
| 184 | t.Fatal("Test configuration failed:", err) |
| 185 | } |
| 186 | if err := os.MkdirAll(filepath.Join(t.testDir, "runtimedir"), os.ModePerm); err != nil { |
| 187 | t.Fatal("Test configuration failed:", err) |
| 188 | } |
| 189 | |
| 190 | t.Cleanup(func() { |
| 191 | if !t.Failed() { |
| 192 | return |
| 193 | } |
| 194 | |
| 195 | t.Log("removing", t.testDir) |
| 196 | assert.NoError(t, os.RemoveAll(t.testDir)) |
| 197 | t.testDir = "" |
| 198 | }) |
| 199 | } |
| 200 | |
| 201 | configPreable := "state_dir " + filepath.Join(t.testDir, "statedir") + "\n" + |
| 202 | "runtime_dir " + filepath.Join(t.testDir, "runtimedir") + "\n\n" |
| 203 | |
| 204 | err := os.WriteFile(filepath.Join(t.testDir, "maddy.conf"), []byte(configPreable+t.cfg), os.ModePerm) |
| 205 | if err != nil { |
| 206 | t.Fatal("Test configuration failed:", err) |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | func (t *T) buildCmd(additionalArgs ...string) *exec.Cmd { |
| 211 | // Assigning 0 by default will make outbound SMTP unusable. |
no test coverage detected