Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ func TestMetrics(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -562,7 +564,9 @@ func TestWorkerMetrics(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -654,7 +658,9 @@ func TestNamedWorkerMetrics(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -745,7 +751,9 @@ func TestAutoWorkerConfig(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -904,8 +912,9 @@ func testSingleIniConfiguration(tester *caddytest.Tester, key string, value stri
}

func TestOsEnv(t *testing.T) {
os.Setenv("ENV1", "value1")
os.Setenv("ENV2", "value2")
require.NoError(t, os.Setenv("ENV1", "value1"))
require.NoError(t, os.Setenv("ENV2", "value2"))

tester := caddytest.NewTester(t)
tester.InitServer(`
{
Expand Down Expand Up @@ -1050,9 +1059,11 @@ func TestMaxWaitTimeWorker(t *testing.T) {
func getStatusCode(url string, t *testing.T) int {
req, err := http.NewRequest("GET", url, nil)
require.NoError(t, err)

resp, err := http.DefaultClient.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
require.NoError(t, resp.Body.Close())

return resp.StatusCode
}

Expand Down Expand Up @@ -1111,7 +1122,9 @@ func TestMultiWorkersMetrics(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -1217,7 +1230,9 @@ func TestDisabledMetrics(t *testing.T) {
// Fetch metrics
resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down Expand Up @@ -1276,7 +1291,9 @@ func TestWorkerRestart(t *testing.T) {

resp, err := http.Get("http://localhost:2999/metrics")
require.NoError(t, err, "failed to fetch metrics")
defer resp.Body.Close()
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})

// Read and parse metrics
metrics := new(bytes.Buffer)
Expand Down