From 011b192a6b987bcc79ed03070d9bb07f616ff153 Mon Sep 17 00:00:00 2001 From: Jarek Kowalski Date: Thu, 24 Mar 2016 17:58:25 -0700 Subject: [PATCH] added version number support --- Makefile | 2 +- cas/format.go | 1 + cas/object_manager.go | 3 +++ cas/object_manager_test.go | 43 ++++++++++++++++++++++---------------- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index bb7f1a0fc..18eb7aa77 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: lint vet build +all: lint vet build test build: go build github.com/kopia/kopia/... diff --git a/cas/format.go b/cas/format.go index 78419be1c..5e58132c4 100644 --- a/cas/format.go +++ b/cas/format.go @@ -2,6 +2,7 @@ // Format describes the format of object data. type Format struct { + Version string `json:"version"` Hash string `json:"hash"` Encryption string `json:"encryption"` Secret []byte `json:"secret,omitempty"` diff --git a/cas/object_manager.go b/cas/object_manager.go index 9fda5b837..fdd06d839 100644 --- a/cas/object_manager.go +++ b/cas/object_manager.go @@ -127,6 +127,9 @@ func NewObjectManager( f Format, options ...ObjectManagerOption, ) (ObjectManager, error) { + if f.Version != "1" { + return nil, fmt.Errorf("unsupported repository version: %v", f.Version) + } mgr := &objectManager{ repository: r, maxInlineBlobSize: f.MaxInlineBlobSize, diff --git a/cas/object_manager_test.go b/cas/object_manager_test.go index 9ab8a8dbb..caa5ad462 100644 --- a/cas/object_manager_test.go +++ b/cas/object_manager_test.go @@ -18,6 +18,7 @@ func testFormat() Format { return Format{ + Version: "1", MaxBlobSize: 200, MaxInlineBlobSize: 20, Hash: "md5", @@ -355,59 +356,65 @@ func TestEndToEndReadAndSeek(t *testing.T) { func TestFormats(t *testing.T) { cases := []struct { format Format - hashes map[string]content.ObjectID + oids map[string]content.ObjectID }{ { format: Format{ - Hash: "md5", + Version: "1", + Hash: "md5", }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "": "Cd41d8cd98f00b204e9800998ecf8427e", "The quick brown fox jumps over the lazy dog": "C9e107d9d372bb6826bd81d3542a419d6", }, }, { format: Format{ - Hash: "hmac-md5", + Version: "1", + Hash: "hmac-md5", }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "": "C74e6f7298a9c2d168935f58c001bad88", "The quick brown fox jumps over the lazy dog": "Cad262969c53bc16032f160081c4a07a0", }, }, { format: Format{ - Hash: "hmac-md5", - Secret: []byte("key"), + Version: "1", + Hash: "hmac-md5", + Secret: []byte("key"), }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "The quick brown fox jumps over the lazy dog": "C80070713463e7749b90c2dc24911e275", }, }, { format: Format{ - Hash: "hmac-sha1", - Secret: []byte("key"), + Version: "1", + Hash: "hmac-sha1", + Secret: []byte("key"), }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "The quick brown fox jumps over the lazy dog": "Cde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9", }, }, { format: Format{ - Hash: "hmac-sha256", - Secret: []byte("key"), + Version: "1", + Hash: "hmac-sha256", + Secret: []byte("key"), }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "The quick brown fox jumps over the lazy dog": "Cf7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8", }, }, { format: Format{ - Hash: "hmac-sha512", - Secret: []byte("key"), + Version: "1", + Hash: "hmac-sha512", + Secret: []byte("key"), }, - hashes: map[string]content.ObjectID{ + oids: map[string]content.ObjectID{ "The quick brown fox jumps over the lazy dog": "Cb42af09057bac1e2d41708e48a902e09b5ff7f12ab428a4fe86653c73dd248fb82f948a549f7b791a5b41915ee4d1ec3935357e4e2317250d0372afa2ebeeb3a", }, }, @@ -423,7 +430,7 @@ func TestFormats(t *testing.T) { continue } - for k, v := range c.hashes { + for k, v := range c.oids { w := mgr.NewWriter() w.Write([]byte(k)) oid, err := w.Result(true)