Browse Source
Add PutMetadata function to storage backends (#171)
Add PutMetadata function to storage backends (#171)
* Add PutMetadata function to storage backends This function is not currently used, but it will be useful for helper scripts that need to regenerate metadata on the fly, especially scripts to migrate between storage backends. In the future, we can also use it to automatically regenerate metadata if it is found to be missing or corrupted. * Add PutMetadata function to storage backend interface and implementations * Rework metadata generation to be more efficient and work better with the PutMetadata function * Add a basic test for metadata generation * Change PutMetadata to take a Metadata type instead It's unlikely that this function is useful if it always regenerates the metadata. Instead, the caller should do that if it needs.pull/176/head
mutantmonkey
6 years ago
committed by
Andrei Marcu
5 changed files with 117 additions and 43 deletions
-
20backends/localfs/localfs.go
-
48backends/s3/s3.go
-
1backends/storage.go
-
62helpers/helpers.go
-
29helpers/helpers_test.go
@ -0,0 +1,29 @@ |
|||
package helpers |
|||
|
|||
import ( |
|||
"strings" |
|||
"testing" |
|||
) |
|||
|
|||
func TestGenerateMetadata(t *testing.T) { |
|||
r := strings.NewReader("This is my test content") |
|||
m, err := GenerateMetadata(r) |
|||
if err != nil { |
|||
t.Fatal(err) |
|||
} |
|||
|
|||
expectedSha256sum := "966152d20a77e739716a625373ee15af16e8f4aec631a329a27da41c204b0171" |
|||
if m.Sha256sum != expectedSha256sum { |
|||
t.Fatalf("Sha256sum was %q instead of expected value of %q", m.Sha256sum, expectedSha256sum) |
|||
} |
|||
|
|||
expectedMimetype := "text/plain" |
|||
if m.Mimetype != expectedMimetype { |
|||
t.Fatalf("Mimetype was %q instead of expected value of %q", m.Mimetype, expectedMimetype) |
|||
} |
|||
|
|||
expectedSize := int64(23) |
|||
if m.Size != expectedSize { |
|||
t.Fatalf("Size was %d instead of expected value of %d", m.Size, expectedSize) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue