From b3c2564730f67e99ef58f8d4e98283680dc96207 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 21 Jul 2017 07:42:41 +0200 Subject: Renamed field Container => Archive in snapshots This is a much better name for what that is --- backup/backup.go | 10 +++++----- objects/object_snapshot.go | 24 ++++++++++++------------ objects/object_snapshot_test.go | 18 +++++++++--------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backup/backup.go b/backup/backup.go index 9c012e0..f578e6f 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -103,13 +103,13 @@ func CreateSnapshot( store storage.Storage, tree_id objects.ObjectId, date time.Time, - container string, + archive string, comment string, ) (objects.ObjectId, error) { return storage.SetObject(store, objects.ToRawObject(&objects.Snapshot{ - Tree: tree_id, - Date: date, - Container: container, - Comment: comment, + Tree: tree_id, + Date: date, + Archive: archive, + Comment: comment, })) } diff --git a/objects/object_snapshot.go b/objects/object_snapshot.go index a161f27..18a534f 100644 --- a/objects/object_snapshot.go +++ b/objects/object_snapshot.go @@ -10,10 +10,10 @@ import ( ) type Snapshot struct { - Tree ObjectId - Date time.Time - Container string - Comment string + Tree ObjectId + Date time.Time + Archive string + Comment string } func (s Snapshot) Type() ObjectType { @@ -29,7 +29,7 @@ func appendKVPair(b []byte, k, v string) []byte { } func (s Snapshot) Payload() (out []byte) { - out = appendKVPair(out, "container", s.Container) + out = appendKVPair(out, "archive", s.Archive) out = appendKVPair(out, "date", s.Date.Format(time.RFC3339)) out = appendKVPair(out, "tree", s.Tree.String()) @@ -44,7 +44,7 @@ func (s Snapshot) Payload() (out []byte) { func (s *Snapshot) FromPayload(payload []byte) error { r := bytes.NewBuffer(payload) - seenContainer := false + seenArchive := false seenDate := false seenTree := false @@ -66,9 +66,9 @@ func (s *Snapshot) FromPayload(payload []byte) error { headerval := strings.TrimSpace(parts[1]) switch parts[0] { - case "container": - s.Container = headerval - seenContainer = true + case "archive": + s.Archive = headerval + seenArchive = true case "date": d, err := time.Parse(time.RFC3339, headerval) if err != nil { @@ -90,8 +90,8 @@ func (s *Snapshot) FromPayload(payload []byte) error { } } - if !seenContainer || !seenDate || !seenTree { - return errors.New("Missing container, date or tree header") + if !seenArchive || !seenDate || !seenTree { + return errors.New("Missing archive, date or tree header") } b := new(bytes.Buffer) @@ -105,7 +105,7 @@ func (s *Snapshot) FromPayload(payload []byte) error { func (a Snapshot) Equals(b Snapshot) bool { return a.Tree.Equals(b.Tree) && - a.Container == b.Container && + a.Archive == b.Archive && a.Date.Equal(b.Date) && a.Comment == b.Comment } diff --git a/objects/object_snapshot_test.go b/objects/object_snapshot_test.go index b610190..df150de 100644 --- a/objects/object_snapshot_test.go +++ b/objects/object_snapshot_test.go @@ -8,14 +8,14 @@ import ( var ( testSnapshotObj = Snapshot{ - Comment: "foo\nbar\nbaz!", - Container: "foo", - Date: time.Date(2017, 07, 01, 21, 40, 00, 0, time.FixedZone("", 2*60*60)), - Tree: genId(0xff), + Archive: "foo", + Comment: "foo\nbar\nbaz!", + Date: time.Date(2017, 07, 01, 21, 40, 00, 0, time.FixedZone("", 2*60*60)), + Tree: genId(0xff), } testSnapshotSerialization = []byte("" + - "container foo\n" + + "archive foo\n" + "date 2017-07-01T21:40:00+02:00\n" + "tree sha3-256:ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n" + "\n" + @@ -46,10 +46,10 @@ func TestUnserializeSnapshot(t *testing.T) { func TestUnserializeSnapshotFailure(t *testing.T) { subtests := []struct{ name, payload string }{ {"empty", ""}, - {"missing tree", "container foo\ndate 2017-07-01T22:02:00+02:00\n"}, - {"missing container", "date 2017-07-01T22:02:00+02:00\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, - {"missing date", "container foo\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, - {"invalid date", "container foo\ndate foobar\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, + {"missing tree", "archive foo\ndate 2017-07-01T22:02:00+02:00\n"}, + {"missing archive", "date 2017-07-01T22:02:00+02:00\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, + {"missing date", "archive foo\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, + {"invalid date", "archive foo\ndate foobar\ntree sha3-256:0000000000000000000000000000000000000000000000000000000000000000\n"}, } for _, subtest := range subtests { -- cgit v1.2.3-70-g09d2