From f290aa36d75b59a71c8e7ade46b4af396c3b9ddd Mon Sep 17 00:00:00 2001 From: Marius Date: Mon, 19 Aug 2019 11:08:24 +0200 Subject: [PATCH] gcsstore: Add storage details --- pkg/gcsstore/gcsstore.go | 6 ++++++ pkg/gcsstore/gcsstore_test.go | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/gcsstore/gcsstore.go b/pkg/gcsstore/gcsstore.go index eb5e5ac..a4fe264 100644 --- a/pkg/gcsstore/gcsstore.go +++ b/pkg/gcsstore/gcsstore.go @@ -63,6 +63,12 @@ func (store GCSStore) NewUpload(info handler.FileInfo) (id string, err error) { info.ID = uid.Uid() } + info.Storage = map[string]string{ + "Type": "gcsstore", + "Bucket": store.Bucket, + "Key": store.keyWithPrefix(info.ID), + } + ctx := context.Background() err = store.writeInfo(ctx, store.keyWithPrefix(info.ID), info) if err != nil { diff --git a/pkg/gcsstore/gcsstore_test.go b/pkg/gcsstore/gcsstore_test.go index 9be72e5..8b0cc5e 100644 --- a/pkg/gcsstore/gcsstore_test.go +++ b/pkg/gcsstore/gcsstore_test.go @@ -22,13 +22,18 @@ const mockBucket = "bucket" const mockSize = 1337 const mockReaderData = "helloworld" -var mockTusdInfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"MetaData":{"foo":"bar"}}`, mockID, mockSize) +var mockTusdInfoJson = fmt.Sprintf(`{"ID":"%s","Size":%d,"MetaData":{"foo":"bar"},"Storage":{"Bucket":"bucket","Key":"%s","Type":"gcsstore"}}`, mockID, mockSize, mockID) var mockTusdInfo = handler.FileInfo{ ID: mockID, Size: mockSize, MetaData: map[string]string{ "foo": "bar", }, + Storage: map[string]string{ + "Type": "gcsstore", + "Bucket": mockBucket, + "Key": mockID, + }, } var mockPartial0 = fmt.Sprintf("%s_0", mockID) @@ -75,7 +80,13 @@ func TestNewUploadWithPrefix(t *testing.T) { assert.Equal(store.Bucket, mockBucket) - data, err := json.Marshal(mockTusdInfo) + info := mockTusdInfo + info.Storage = map[string]string{ + "Type": "gcsstore", + "Bucket": mockBucket, + "Key": "/path/to/file/" + mockID, + } + data, err := json.Marshal(info) assert.Nil(err) r := bytes.NewReader(data)