ipn: test TestFileStore in a fresh subdirectory

Fixes #2923

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/2941/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 21e9f98fc1
commit 3a72ebb109

@ -5,8 +5,7 @@
package ipn package ipn
import ( import (
"io/ioutil" "path/filepath"
"os"
"testing" "testing"
"tailscale.com/tstest" "tailscale.com/tstest"
@ -87,15 +86,8 @@ func TestMemoryStore(t *testing.T) {
func TestFileStore(t *testing.T) { func TestFileStore(t *testing.T) {
tstest.PanicOnLog() tstest.PanicOnLog()
f, err := ioutil.TempFile("", "test_ipn_store") dir := t.TempDir()
if err != nil { path := filepath.Join(dir, "test-file-store.conf")
t.Fatal(err)
}
path := f.Name()
f.Close()
if err := os.Remove(path); err != nil {
t.Fatal(err)
}
store, err := NewFileStore(path) store, err := NewFileStore(path)
if err != nil { if err != nil {
@ -115,13 +107,14 @@ func TestFileStore(t *testing.T) {
"foo": "bar", "foo": "bar",
"baz": "quux", "baz": "quux",
} }
for id, want := range expected { for key, want := range expected {
bs, err := store.ReadState(id) bs, err := store.ReadState(key)
if err != nil { if err != nil {
t.Errorf("reading %q (2nd store): %v", id, err) t.Errorf("reading %q (2nd store): %v", key, err)
continue
} }
if string(bs) != want { if string(bs) != want {
t.Errorf("reading %q (2nd store): got %q, want %q", id, string(bs), want) t.Errorf("reading %q (2nd store): got %q, want %q", key, bs, want)
} }
} }
} }

Loading…
Cancel
Save