fs use binary (um)marshaler

This commit is contained in:
Ilia Denisov
2025-09-23 22:02:21 +03:00
parent 4d733ae741
commit c777ba91dd
4 changed files with 51 additions and 10 deletions
+6 -3
View File
@@ -58,7 +58,8 @@ func TestWrite(t *testing.T) {
{path: "/" + dirName, err: "wrong type"},
} {
t.Run(tc.path, func(t *testing.T) {
err = fs.Write(tc.path, []byte{0, 1, 2, 3})
sd := &sampleData{[]byte{0, 1, 2, 3}}
err = fs.Write(tc.path, sd)
if tc.err == "" {
if err != nil {
assert.Fail(t, "not expecting an error", "write to file %s: %s", tc.path, err)
@@ -122,7 +123,8 @@ func TestRead(t *testing.T) {
}
}()
}
_, err = fs.Read(tc.path)
sd := new(sampleData)
err = fs.Read(tc.path, sd)
if tc.err == "" {
if err != nil {
assert.Fail(t, "read: not expecting an error, got: "+err.Error())
@@ -147,7 +149,8 @@ func TestWriteErrorWithoutLock(t *testing.T) {
defer cleanup()
fs, err := NewFileStorage(root)
assert.NoError(t, err, "create file storage")
err = fs.Write("some/path", []byte{0, 1, 2, 3})
sd := &sampleData{[]byte{0, 1, 2, 3}}
err = fs.Write("some/path", sd)
assert.Error(t, err, "should return error when no lock acquired")
assert.True(t, strings.Contains(err.Error(), "lock must be acquired"), "should return missing lock error")
}