schema: rewrite symlink test to not delete testdata, not use asserts

Change-Id: I238ee5d55203f5c53b294d82e2cc626c4ef78ef2
This commit is contained in:
Brad Fitzpatrick 2014-07-13 10:02:30 -07:00
parent 06cd39ebb8
commit af4df6f8c5
1 changed files with 24 additions and 16 deletions

View File

@ -63,26 +63,34 @@ func TestRegularFile(t *testing.T) {
} }
func TestSymlink(t *testing.T) { func TestSymlink(t *testing.T) {
// We create the symlink now because make.go does not mirror td, err := ioutil.TempDir("", "")
// symlinks properly, and it is less intrusive to do that here. if err != nil {
defer os.RemoveAll("testdata") t.Fatal(err)
err := os.Mkdir("testdata", 0755) }
AssertNil(t, err, "Mkdir") defer os.RemoveAll(td)
err = os.Chdir("testdata")
AssertNil(t, err, "Chdir") symFile := filepath.Join(td, "test-symlink")
err = os.Symlink("test-target", "test-symlink") if err := os.Symlink("test-target", symFile); err != nil {
AssertNil(t, err, "creating test-symlink") t.Fatal(err)
err = os.Chdir("..") }
AssertNil(t, err, "Chdir")
fileName := filepath.Join("testdata", "test-symlink") // Shouldn't be accessed:
fi, err := os.Lstat(fileName) if err := ioutil.WriteFile(filepath.Join(td, "test-target"), []byte("foo bar"), 0644); err != nil {
AssertNil(t, err, "test-symlink stat") t.Fatal(err)
m := NewCommonFileMap(fileName, fi) }
fi, err := os.Lstat(symFile)
if err != nil {
t.Fatal(err)
}
m := NewCommonFileMap(symFile, fi)
json, err := m.JSON() json, err := m.JSON()
if err != nil { if err != nil {
t.Fatalf("Unexpected error: %v", err) 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) { func TestUtf8StrLen(t *testing.T) {