aboutsummaryrefslogtreecommitdiff
path: root/filesystem/filesystem_test.go
diff options
context:
space:
mode:
authorJoe Richey <joerichey@google.com>2019-10-23 22:06:13 -0700
committerJoe Richey <joerichey@google.com>2019-10-23 22:06:13 -0700
commit83828388b4195cb5b2de5dad937d19208c1fa7ff (patch)
treef0111ce2660074b9eedb578cbeb42684858f602d /filesystem/filesystem_test.go
parentdb31d21e9cab31dff152082a4e88217d447970c4 (diff)
filesystem: Move test-only code to test files
This makes it easier to understand which code is actually invoked by the command-line tool.
Diffstat (limited to 'filesystem/filesystem_test.go')
-rw-r--r--filesystem/filesystem_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go
index 50c3920..b85ead5 100644
--- a/filesystem/filesystem_test.go
+++ b/filesystem/filesystem_test.go
@@ -21,6 +21,7 @@ package filesystem
import (
"io/ioutil"
+ "log"
"os"
"path/filepath"
"testing"
@@ -110,6 +111,22 @@ func TestRemoveAllMetadata(t *testing.T) {
}
}
+// loggedLstat runs os.Lstat (doesn't dereference trailing symlink), but it logs
+// the error if lstat returns any error other than nil or IsNotExist.
+func loggedLstat(name string) (os.FileInfo, error) {
+ info, err := os.Lstat(name)
+ if err != nil && !os.IsNotExist(err) {
+ log.Print(err)
+ }
+ return info, err
+}
+
+// isSymlink returns true if the path exists and is that of a symlink.
+func isSymlink(path string) bool {
+ info, err := loggedLstat(path)
+ return err == nil && info.Mode()&os.ModeSymlink != 0
+}
+
// Test that when MOUNTPOINT/.fscrypt is a pre-created symlink, fscrypt will
// create/delete the metadata at the location pointed to by the symlink.
//