diff options
| author | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-06-21 09:52:40 -0700 |
|---|---|---|
| committer | Joe Richey joerichey@google.com <joerichey@google.com> | 2017-06-28 14:06:52 -0700 |
| commit | 77b226a90ef70b77ca556830528c013a23b01e57 (patch) | |
| tree | b351dbb427ed62550f2440b8d56249bdcbbca96a /filesystem/filesystem_test.go | |
| parent | 07341f3966675e4875f8cad3c8d86ae502de6d4d (diff) | |
Change error handling to new package
This commit changes the error handing for the crypto, filesystem,
metadata, pam, and util packages to use the error handling library
github.com/pkg/errors. This means elimination of the FSError type, an
increased use of wrapping errors (as opposed to logging), switching
on the Cause() of an error (as opposed to its value), and improving our
integration tests involving TEST_FILESYSTEM_ROOT.
This commit also fixes a few bugs with the keyring code to ensure that
our {Find|Remove|Insert}PolicyKey functions are always operating on the
same keyring. The check for filesystem support has been moved from the
filesystem package to the metadata package. Finally, the API for the
filesystem package has been slightly modified:
* filesystem.AllFilesystems() now returns all the filesystems in
sorted order
* certain path methods are now public
O_SYNC is also removed for writing the metadata. We don't get that much
from syncing the metadata, as the actual file data could also be
corrupted by and IO error. The sync operation is also occasionally very
slow (~3 seconds) and can be unfriendly to battery life.
Change-Id: I392c2655141714b16dfdbc84ac09780072be2cf0
Diffstat (limited to 'filesystem/filesystem_test.go')
| -rw-r--r-- | filesystem/filesystem_test.go | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/filesystem/filesystem_test.go b/filesystem/filesystem_test.go index 33ab10b..bcf4f38 100644 --- a/filesystem/filesystem_test.go +++ b/filesystem/filesystem_test.go @@ -20,14 +20,16 @@ package filesystem import ( - "fmt" "os" "path/filepath" "reflect" "testing" + "github.com/pkg/errors" + . "fscrypt/crypto" . "fscrypt/metadata" + . "fscrypt/util" ) var ( @@ -37,17 +39,14 @@ var ( wrappedPolicyKey, _ = Wrap(fakeProtectorKey, fakePolicyKey) ) -// Gets the mount corresponding to TEST_FILESYSTEM_ROOT +// Gets the mount corresponding to the integration test path. func getTestMount() (*Mount, error) { - mountpoint := os.Getenv("TEST_FILESYSTEM_ROOT") - if mountpoint == "" { - return nil, fmt.Errorf("set TEST_FILESYSTEM_ROOT to a mountpoint") - } - mnt, err := GetMount(mountpoint) + mountpoint, err := TestPath() if err != nil { - return nil, fmt.Errorf("bad TEST_FILESYSTEM_ROOT: %s", err) + return nil, err } - return mnt, nil + mnt, err := GetMount(mountpoint) + return mnt, errors.Wrapf(err, TestEnvVarName) } func getFakeProtector() *ProtectorData { @@ -92,7 +91,7 @@ func TestSetup(t *testing.T) { t.Error(err) } - os.RemoveAll(mnt.baseDir()) + os.RemoveAll(mnt.BaseDir()) } // Tests that we can remove all of the metadata @@ -106,7 +105,7 @@ func TestRemoveAllMetadata(t *testing.T) { t.Fatal(err) } - if isDir(mnt.baseDir()) { + if isDir(mnt.BaseDir()) { t.Error("metadata was not removed") } } @@ -279,7 +278,7 @@ func TestLinkedProtector(t *testing.T) { // Get the protector though the second system _, err = fakeMnt.GetRegularProtector(protector.ProtectorDescriptor) - if err == nil || err.(FSError).Err != ErrNoMetadata { + if errors.Cause(err) != ErrNoMetadata { t.Fatal(err) } |