From bde2a38931b46bee2d85ddc73f231489afa8bf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 24 Jan 2022 16:38:17 +0100 Subject: [PATCH] Improve filestore test --- files/filestore_memory.go | 1 + files/filestore_test.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/files/filestore_memory.go b/files/filestore_memory.go index 0640c90..ee9ac51 100644 --- a/files/filestore_memory.go +++ b/files/filestore_memory.go @@ -61,6 +61,7 @@ func (s *MemoryFileStore) Get(id string) (*File, error) { MaxViews: fd.MaxViews, ExpiresOn: fd.ExpiresOn, Body: io.NopCloser(&fd.Body), + FileSize: fd.FileSize, } return f, nil diff --git a/files/filestore_test.go b/files/filestore_test.go index a27ea91..a3e9c4d 100644 --- a/files/filestore_test.go +++ b/files/filestore_test.go @@ -21,9 +21,10 @@ func RunFilestoreTest(s files.FileStore, t *testing.T) { bodyBuf.Write([]byte(dataString)) body := io.NopCloser(bodyBuf) f := &files.File{ - ID: id, - MaxViews: 0, - Body: body, + ID: id, + MaxViews: 99, + Body: body, + ExpiresOn: time.Now().Add(99 * time.Second), } err := s.Store(f) @@ -50,6 +51,17 @@ func RunFilestoreTest(s files.FileStore, t *testing.T) { if retrievedBuf.String() != dataString { t.Fatalf("Data from retrieved body mismatch. Got %s want %s", retrievedBuf.String(), dataString) } + expected := &files.File{ + ID: f.ID, + MaxViews: f.MaxViews, + ExpiresOn: f.ExpiresOn, + FileSize: int64(len(dataString)), + } + + ignoreBody := cmp.FilterPath(func(p cmp.Path) bool { return p.String() == "Body" }, cmp.Ignore()) + if diff := cmp.Diff(retrieved, expected, ignoreBody); diff != "" { + t.Errorf("File comparison failed: %s", diff) + } // List ids, err := s.List()