all: use tstest.Replace more

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2023-03-04 12:04:55 -08:00
committed by Maisem Ali
parent 57a44846ae
commit 1a30b2d73f
12 changed files with 35 additions and 58 deletions

View File

@ -16,6 +16,8 @@ import (
"strings"
"testing"
"time"
"tailscale.com/tstest"
)
func TestSynologyProxyFromConfigCached(t *testing.T) {
@ -24,9 +26,7 @@ func TestSynologyProxyFromConfigCached(t *testing.T) {
t.Fatal(err)
}
var orig string
orig, synologyProxyConfigPath = synologyProxyConfigPath, filepath.Join(t.TempDir(), "proxy.conf")
defer func() { synologyProxyConfigPath = orig }()
tstest.Replace(t, &synologyProxyConfigPath, filepath.Join(t.TempDir(), "proxy.conf"))
t.Run("no config file", func(t *testing.T) {
if _, err := os.Stat(synologyProxyConfigPath); err == nil {
@ -160,11 +160,9 @@ func TestSynologyProxiesFromConfig(t *testing.T) {
openReader io.ReadCloser
openErr error
)
var origOpen func() (io.ReadCloser, error)
origOpen, openSynologyProxyConf = openSynologyProxyConf, func() (io.ReadCloser, error) {
tstest.Replace(t, &openSynologyProxyConf, func() (io.ReadCloser, error) {
return openReader, openErr
}
defer func() { openSynologyProxyConf = origOpen }()
})
t.Run("with config", func(t *testing.T) {
mc := &mustCloser{Reader: strings.NewReader(`