Improve filestore test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
1a3ebcb1df
commit
bde2a38931
@ -61,6 +61,7 @@ func (s *MemoryFileStore) Get(id string) (*File, error) {
|
|||||||
MaxViews: fd.MaxViews,
|
MaxViews: fd.MaxViews,
|
||||||
ExpiresOn: fd.ExpiresOn,
|
ExpiresOn: fd.ExpiresOn,
|
||||||
Body: io.NopCloser(&fd.Body),
|
Body: io.NopCloser(&fd.Body),
|
||||||
|
FileSize: fd.FileSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
return f, nil
|
return f, nil
|
||||||
|
@ -22,8 +22,9 @@ func RunFilestoreTest(s files.FileStore, t *testing.T) {
|
|||||||
body := io.NopCloser(bodyBuf)
|
body := io.NopCloser(bodyBuf)
|
||||||
f := &files.File{
|
f := &files.File{
|
||||||
ID: id,
|
ID: id,
|
||||||
MaxViews: 0,
|
MaxViews: 99,
|
||||||
Body: body,
|
Body: body,
|
||||||
|
ExpiresOn: time.Now().Add(99 * time.Second),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.Store(f)
|
err := s.Store(f)
|
||||||
@ -50,6 +51,17 @@ func RunFilestoreTest(s files.FileStore, t *testing.T) {
|
|||||||
if retrievedBuf.String() != dataString {
|
if retrievedBuf.String() != dataString {
|
||||||
t.Fatalf("Data from retrieved body mismatch. Got %s want %s", 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
|
// List
|
||||||
ids, err := s.List()
|
ids, err := s.List()
|
||||||
|
Loading…
Reference in New Issue
Block a user