]> git.giacomolli.uk - onechat/blobdiff - syncer_test.go
Complete context on forwarded local errors
[onechat] / syncer_test.go
index 16f334530fc5def0b111ea702589926b3b209274..8eeb1eeee55213541def549d08b8b4772b0508ee 100644 (file)
@@ -76,16 +76,17 @@ func TestFlushWithoutWritesNeedsNoSync(t *testing.T) {
 }
 
 func TestAFailedSyncFailsEachLaterFlush(t *testing.T) {
+       failure := errors.New("disk error")
        s := newSyncer(func() error {
-               return errors.New("disk error")
+               return failure
        })
 
        s.Written()
-       require.ErrorContains(t, s.Flush(t.Context()), "disk error")
+       require.ErrorIs(t, s.Flush(t.Context()), failure)
 
        s.Written()
-       require.ErrorContains(t, s.Flush(t.Context()), "disk error")
-       require.ErrorContains(t, s.Close(), "disk error")
+       require.ErrorIs(t, s.Flush(t.Context()), failure)
+       require.ErrorIs(t, s.Close(), failure)
 }
 
 func TestMemoryFlushSyncsTheChat(t *testing.T) {
@@ -148,6 +149,13 @@ type SyncerGatedSync struct {
        release chan struct{}
 }
 
+func newSyncerGatedSync() *SyncerGatedSync {
+       return &SyncerGatedSync{
+               started: make(chan struct{}, 100),
+               release: make(chan struct{}),
+       }
+}
+
 func (g *SyncerGatedSync) Sync() error {
        g.mutex.Lock()
 
@@ -184,13 +192,6 @@ func (g *SyncerGatedSync) Count() int {
        return g.count
 }
 
-func newSyncerGatedSync() *SyncerGatedSync {
-       return &SyncerGatedSync{
-               started: make(chan struct{}, 100),
-               release: make(chan struct{}),
-       }
-}
-
 // syncerRunKilledWriter starts the writer child on the chat in root, kills it
 // with SIGKILL after it acknowledged count messages, and returns the number of
 // messages that it acknowledged.