From 44c2c7aeda3de09a405ed06aadacbc2c0c7f2a67 Mon Sep 17 00:00:00 2001 From: "Joe Richey joerichey@google.com" Date: Tue, 23 May 2017 18:38:38 -0700 Subject: metadata: reorganize and add consistency checks This commit adds in IsValid() checks for the metadata structures that let us enforce stronger invariants than those imposed by the protobuf package. The main uses of this will be to check that metadata is valid before writing it to the filesystem, and to check that the filesystem contains valid metadata before returning it to the user. These functions also will log the exact reason if the validity checks fail. To have these checks in the metadata package, all of the various constants have been moved to a single metadata/constants.go file. The uses of these constants were changed accordingly. Finally, this commit standardizes our use of errors so that they always begin with an appropriate prefix. Change-Id: I99008e2ee803ebe5f6236eb8d83fc83efcd22718 --- metadata/policy_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'metadata/policy_test.go') diff --git a/metadata/policy_test.go b/metadata/policy_test.go index 593f3da..6dc2567 100644 --- a/metadata/policy_test.go +++ b/metadata/policy_test.go @@ -34,12 +34,13 @@ var goodPolicy = &PolicyData{ Options: DefaultOptions, } -// Creates a temporary directory in BASE_TEST_DIR for testing. Fails if the -// base directory is not specified. +// Creates a temporary directory in TEST_FILESYSTEM_ROOT for testing. Fails if +// the root directory is not specified. func createTestDirectory() (directory string, err error) { - baseDirectory := os.Getenv("BASE_TEST_DIR") + baseDirectory := os.Getenv("TEST_FILESYSTEM_ROOT") if s, err := os.Stat(baseDirectory); err != nil || !s.IsDir() { - return "", fmt.Errorf("invalid directory %q. Set BASE_TEST_DIR to be a valid directory", baseDirectory) + return "", fmt.Errorf("invalid directory %q: "+ + "set TEST_FILESYSTEM_ROOT to be a valid directory", baseDirectory) } directoryPath := filepath.Join(baseDirectory, "test") -- cgit v1.2.3