From af4df6f8c51b890864eaf96162047ffb0cdb71b0 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 13 Jul 2014 10:02:30 -0700 Subject: [PATCH] schema: rewrite symlink test to not delete testdata, not use asserts Change-Id: I238ee5d55203f5c53b294d82e2cc626c4ef78ef2 --- pkg/schema/schema_test.go | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pkg/schema/schema_test.go b/pkg/schema/schema_test.go index 58098fea2..dffd6988d 100644 --- a/pkg/schema/schema_test.go +++ b/pkg/schema/schema_test.go @@ -63,26 +63,34 @@ func TestRegularFile(t *testing.T) { } func TestSymlink(t *testing.T) { - // We create the symlink now because make.go does not mirror - // symlinks properly, and it is less intrusive to do that here. - defer os.RemoveAll("testdata") - err := os.Mkdir("testdata", 0755) - AssertNil(t, err, "Mkdir") - err = os.Chdir("testdata") - AssertNil(t, err, "Chdir") - err = os.Symlink("test-target", "test-symlink") - AssertNil(t, err, "creating test-symlink") - err = os.Chdir("..") - AssertNil(t, err, "Chdir") - fileName := filepath.Join("testdata", "test-symlink") - fi, err := os.Lstat(fileName) - AssertNil(t, err, "test-symlink stat") - m := NewCommonFileMap(fileName, fi) + td, err := ioutil.TempDir("", "") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(td) + + symFile := filepath.Join(td, "test-symlink") + if err := os.Symlink("test-target", symFile); err != nil { + t.Fatal(err) + } + + // Shouldn't be accessed: + if err := ioutil.WriteFile(filepath.Join(td, "test-target"), []byte("foo bar"), 0644); err != nil { + t.Fatal(err) + } + + fi, err := os.Lstat(symFile) + if err != nil { + t.Fatal(err) + } + m := NewCommonFileMap(symFile, fi) json, err := m.JSON() if err != nil { t.Fatalf("Unexpected error: %v", err) } - t.Logf("Got json for symlink file: [%s]\n", json) + if strings.Contains(string(json), "unixPermission") { + t.Errorf("JSON unexpectedly contains unixPermission: [%s]\n", json) + } } func TestUtf8StrLen(t *testing.T) {