]> git.giacomolli.uk - onechat/blobdiff - log_test.go
Check operation context on returned errors
[onechat] / log_test.go
index 97d28a5bc47e7ba765a7cb2a96575e92d0beb0b5..e8e07ac2ff0ad58a7b831aff6abea50c5af12ffe 100644 (file)
@@ -62,7 +62,7 @@ func TestLogBuildsAMissingIndexAgain(t *testing.T) {
        require.NoError(t, log.Close())
 
        // A missing index, and an index that a crash cut in a record.
-       for _, cut := range []func(string) error{os.Remove, truncateToOneAndAHalf} {
+       for _, cut := range []func(string) error{os.Remove, logTruncateToOneAndAHalf} {
                require.NoError(t, cut(filepath.Join(root, "index", "main.idx")))
 
                log, err = openLog(t.Context(), root, clock.Now)
@@ -95,11 +95,11 @@ func TestLogWritesOneFilePerDay(t *testing.T) {
 
        first, err := os.ReadFile(filepath.Join(root, "main", "2026-01-01.jsonl"))
        require.NoError(t, err)
-       require.Equal(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first))
+       require.JSONEq(t, `{"i":0,"kind":"user","text":"first day","size":9,"date":"2026-01-01T12:00:00Z"}`+"\n", string(first))
 
        second, err := os.ReadFile(filepath.Join(root, "main", "2026-01-02.jsonl"))
        require.NoError(t, err)
-       require.Equal(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second))
+       require.JSONEq(t, `{"i":1,"kind":"user","text":"second day","size":10,"date":"2026-01-02T12:00:00Z"}`+"\n", string(second))
 }
 
 func TestLogAllowsOneWriter(t *testing.T) {
@@ -193,7 +193,7 @@ func TestLogRejectsAnIncompleteLineBeforeTheLastDay(t *testing.T) {
        require.ErrorContains(t, err, "ends in an incomplete line")
 }
 
-// truncateToOneAndAHalf cuts the index at path in its second record.
-func truncateToOneAndAHalf(path string) error {
+// logTruncateToOneAndAHalf cuts the index at path in its second record.
+func logTruncateToOneAndAHalf(path string) error {
        return os.Truncate(path, positionBytes+positionBytes/2)
 }