@marcel91200 / caddy Mirror · read-only / commits / f8143a3a
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 12, 17:00 UTC

tests: uses testing.TB interface for helper to be able to use test server in benchmarks. (#6103)

José Carlos Chávez committed Feb 20, 2024 at 23:04 UTC f8143a3af15fb1042dc95791969105eb5b3e9cb2
1 file changed +6 -6
caddytest/caddytest.go
+6 -6
@@ -60,11 +60,11 @@ var (
60 type Tester struct {
61 Client *http.Client
62 configLoaded bool
63 - t *testing.T
63 + t testing.TB
64 }
65
66 // NewTester will create a new testing client with an attached cookie jar
67 -func NewTester(t *testing.T) *Tester {
67 +func NewTester(t testing.TB) *Tester {
68 jar, err := cookiejar.New(nil)
69 if err != nil {
70 t.Fatalf("failed to create cookiejar: %s", err)
@@ -229,7 +229,7 @@ const initConfig = `{
229
230 // validateTestPrerequisites ensures the certificates are available in the
231 // designated path and Caddy sub-process is running.
232 -func validateTestPrerequisites(t *testing.T) error {
232 +func validateTestPrerequisites(t testing.TB) error {
233 // check certificates are found
234 for _, certName := range Default.Certifcates {
235 if _, err := os.Stat(getIntegrationDir() + certName); errors.Is(err, fs.ErrNotExist) {
@@ -373,7 +373,7 @@ func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, e
373 }
374
375 // CompareAdapt adapts a config and then compares it against an expected result
376 -func CompareAdapt(t *testing.T, filename, rawConfig string, adapterName string, expectedResponse string) bool {
376 +func CompareAdapt(t testing.TB, filename, rawConfig string, adapterName string, expectedResponse string) bool {
377 cfgAdapter := caddyconfig.GetAdapter(adapterName)
378 if cfgAdapter == nil {
379 t.Logf("unrecognized config adapter '%s'", adapterName)
@@ -432,7 +432,7 @@ func CompareAdapt(t *testing.T, filename, rawConfig string, adapterName string,
432 }
433
434 // AssertAdapt adapts a config and then tests it against an expected result
435 -func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) {
435 +func AssertAdapt(t testing.TB, rawConfig string, adapterName string, expectedResponse string) {
436 ok := CompareAdapt(t, "Caddyfile", rawConfig, adapterName, expectedResponse)
437 if !ok {
438 t.Fail()
@@ -441,7 +441,7 @@ func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedRes
441
442 // Generic request functions
443
444 -func applyHeaders(t *testing.T, req *http.Request, requestHeaders []string) {
444 +func applyHeaders(t testing.TB, req *http.Request, requestHeaders []string) {
445 requestContentType := ""
446 for _, requestHeader := range requestHeaders {
447 arr := strings.SplitAfterN(requestHeader, ":", 2)