MCPcopy Index your code
hub / github.com/OpenListTeam/OpenList / TestMultiFileCache

Function TestMultiFileCache

internal/hybrid_cache/file_test.go:56–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestMultiFileCache(t *testing.T) {
57 prevConf := conf.Conf
58 t.Cleanup(func() {
59 conf.Conf = prevConf
60 })
61 conf.Conf = &conf.Config{}
62 f := hybrid_cache.MultiFileStore{}
63 defer f.Close()
64 t.Run("ReadAt", func(t *testing.T) {
65 _, err := f.ReadAt(make([]byte, 1), 20)
66 if err != nil && !errors.Is(err, io.EOF) {
67 t.Error(err)
68 }
69 })
70 t.Run("WriteAt", func(t *testing.T) {
71 err := f.GrowTo(15)
72 if err != nil {
73 t.Errorf("truncate err=%v", err)
74 return
75 }
76 n, err := f.WriteAt([]byte("abc"), 10)
77 if err != nil {
78 t.Errorf("write n=%d err=%v", n, err)
79 return
80 }
81
82 err = f.GrowTo(30)
83 if err != nil {
84 t.Errorf("truncate err=%v", err)
85 return
86 }
87 _, _ = f.WriteAt([]byte("123"), 15)
88
89 b := append(make([]byte, 17), []byte("def")...)
90 b[0] = 'a'
91 rn, rerr := f.ReadAt(b, 8)
92 if rn != len(b) || rerr != nil {
93 t.Fatalf("read n=%d err=%v", rn, rerr)
94 }
95 want := []byte{0, 0, 'a', 'b', 'c', 0, 0, '1', '2', '3'}
96 want = append(want, make([]byte, 10)...)
97 if !bytes.Equal(b, want) {
98 t.Fatalf("unexpected content: got %v want %v", b, want)
99 }
100 })
101}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
ReadAtMethod · 0.95
GrowToMethod · 0.95
WriteAtMethod · 0.95
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected