aboutsummaryrefslogtreecommitdiff
path: root/metadata/config_test.go
diff options
context:
space:
mode:
authorJoe Richey joerichey@google.com <joerichey@google.com>2017-05-23 18:38:38 -0700
committerJoe Richey joerichey@google.com <joerichey@google.com>2017-05-31 12:35:28 -0700
commit44c2c7aeda3de09a405ed06aadacbc2c0c7f2a67 (patch)
tree74bd0fccf5c23a739b434893e1d02c16e0153fca /metadata/config_test.go
parent4b6d0ce14b8553a93b2d14fd858dfd35bfd61104 (diff)
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
Diffstat (limited to 'metadata/config_test.go')
-rw-r--r--metadata/config_test.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/metadata/config_test.go b/metadata/config_test.go
index 1903785..206098e 100644
--- a/metadata/config_test.go
+++ b/metadata/config_test.go
@@ -20,6 +20,7 @@
package metadata
import (
+ "bytes"
"reflect"
"testing"
)
@@ -42,27 +43,31 @@ var testConfigString = `{
"memory": "4096",
"parallelism": "8"
},
+ "compatibility": "",
"options": {
"padding": "32",
- "contents_mode": "XTS",
- "filenames_mode": "CTS"
+ "contents": "XTS",
+ "filenames": "CTS"
}
-}`
+}
+`
// Makes sure that writing a config and reading it back gives the same thing.
func TestWrite(t *testing.T) {
- str, err := WriteConfig(testConfig)
+ var b bytes.Buffer
+ err := WriteConfig(testConfig, &b)
if err != nil {
t.Fatal(err)
}
- t.Logf("json encoded config:\n%s", str)
- if str != testConfigString {
+ t.Logf("json encoded config:\n%s", b.String())
+ if b.String() != testConfigString {
t.Errorf("did not match: %s", testConfigString)
}
}
func TestRead(t *testing.T) {
- cfg, err := ReadConfig(testConfigString)
+ buf := bytes.NewBufferString(testConfigString)
+ cfg, err := ReadConfig(buf)
if err != nil {
t.Fatal(err)
}