tstest: add method to Replace values for tests

We have many function pointers that we replace for the duration of test and
restore it on test completion, add method to do that.

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2023-03-03 16:18:59 -08:00
committed by Maisem Ali
parent 12100320d2
commit b9ebf7cf14
5 changed files with 48 additions and 12 deletions

View File

@ -22,6 +22,7 @@ import (
"tailscale.com/net/stun"
"tailscale.com/net/stun/stuntest"
"tailscale.com/tailcfg"
"tailscale.com/tstest"
)
func TestHairpinSTUN(t *testing.T) {
@ -679,9 +680,7 @@ func TestNoCaptivePortalWhenUDP(t *testing.T) {
}
})
oldTransport := noRedirectClient.Transport
t.Cleanup(func() { noRedirectClient.Transport = oldTransport })
noRedirectClient.Transport = tr
tstest.Replace(t, &noRedirectClient.Transport, http.RoundTripper(tr))
stunAddr, cleanup := stuntest.Serve(t)
defer cleanup()