SIGN IN SIGN UP

envknob: add SetenvForTest helper for safe environment variable handling

Our tests are inconsistent in how they set environment variables and cleanup.
Missing cleanup logic can leak environment variable state across tests and
change the behaviour of subsequent tests.

This recently caused flakes in feature/acme, where `TestGetCertPEMWithValidity`
leaked `TS_CERT_SHARE_MODE` and `TestAsyncRenewalDedup` to fail inconsistently.

To fix the immediate flake and prevent future leaks, introduce a `SetenvForTest`
helper that handles setting and cleaning up environment variables in tests.

Fixes #20902

Change-Id: I9f8ef45ec875d66034cfd0054311bd69b67e2243
Signed-off-by: Alex Chan <alexc@tailscale.com>
A
Alex Chan committed
468241a13f945a7e852607d49edddb1a090c4f7d
Parent: 86c1787
Committed by Alex Chan <alex@alexwlchan.net> on 8/19/2026, 11:22:26 AM