fix: resolve errcheck warnings in security_test.go
Use t.Setenv for env var management in tests.
This commit is contained in:
@@ -53,8 +53,7 @@ func TestSecurityHeaders(t *testing.T) {
|
||||
|
||||
func TestSecurityHeaders_HSTS(t *testing.T) {
|
||||
// Test in production mode
|
||||
os.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
defer os.Unsetenv(c.EnvVarGOEnv)
|
||||
t.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
|
||||
handler := SecurityHeaders(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
@@ -71,7 +70,7 @@ func TestSecurityHeaders_HSTS(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test in development mode
|
||||
os.Setenv(c.EnvVarGOEnv, c.EnvDevelopment)
|
||||
t.Setenv(c.EnvVarGOEnv, c.EnvDevelopment)
|
||||
|
||||
w = httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
@@ -474,7 +473,7 @@ func TestCacheControl(t *testing.T) {
|
||||
}))
|
||||
|
||||
// Development mode
|
||||
os.Unsetenv(c.EnvVarGOEnv)
|
||||
_ = os.Unsetenv(c.EnvVarGOEnv)
|
||||
req := httptest.NewRequest(http.MethodGet, "/static/file.css", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
@@ -484,8 +483,7 @@ func TestCacheControl(t *testing.T) {
|
||||
}
|
||||
|
||||
// Production mode
|
||||
os.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
defer os.Unsetenv(c.EnvVarGOEnv)
|
||||
t.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
|
||||
w = httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
@@ -501,7 +499,7 @@ func TestDynamicCacheControl(t *testing.T) {
|
||||
}))
|
||||
|
||||
// Development mode - no cache
|
||||
os.Unsetenv(c.EnvVarGOEnv)
|
||||
_ = os.Unsetenv(c.EnvVarGOEnv)
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
@@ -511,8 +509,7 @@ func TestDynamicCacheControl(t *testing.T) {
|
||||
}
|
||||
|
||||
// Production mode - short cache
|
||||
os.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
defer os.Unsetenv(c.EnvVarGOEnv)
|
||||
t.Setenv(c.EnvVarGOEnv, c.EnvProduction)
|
||||
|
||||
w = httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
|
||||
Reference in New Issue
Block a user