MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / TestFileReader

Function TestFileReader

internal/caches/reader_file_test.go:10–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestFileReader(t *testing.T) {
11 var storage = NewFileStorage(&serverconfigs.HTTPCachePolicy{
12 Id: 1,
13 IsOn: true,
14 Options: map[string]interface{}{
15 "dir": Tea.Root + "/caches",
16 },
17 })
18
19 defer storage.Stop()
20
21 err := storage.Init()
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 _, path, _ := storage.keyPath("my-key")
27
28 fp, err := os.Open(path)
29 if err != nil {
30 if os.IsNotExist(err) {
31 t.Log("file '" + path + "' not exists")
32 return
33 }
34 t.Fatal(err)
35 }
36 defer func() {
37 _ = fp.Close()
38 }()
39 reader := NewFileReader(fp)
40 err = reader.Init()
41 if err != nil {
42 t.Fatal(err)
43 }
44
45 t.Log(reader.Status())
46
47 buf := make([]byte, 10)
48 err = reader.ReadHeader(buf, func(n int) (goNext bool, err error) {
49 t.Log("header:", string(buf[:n]))
50 return true, nil
51 })
52 if err != nil {
53 t.Fatal(err)
54 }
55
56 err = reader.ReadBody(buf, func(n int) (goNext bool, err error) {
57 t.Log("body:", string(buf[:n]))
58 return true, nil
59 })
60 if err != nil {
61 t.Fatal(err)
62 }
63}
64
65func TestFileReader_ReadHeader(t *testing.T) {
66 var path = "/Users/WorkSpace/EdgeProject/EdgeCache/p43/12/6b/126bbed90fc80f2bdfb19558948b0d49.cache"

Callers

nothing calls this directly

Calls 12

InitMethod · 0.95
StatusMethod · 0.95
ReadHeaderMethod · 0.95
ReadBodyMethod · 0.95
NewFileStorageFunction · 0.85
keyPathMethod · 0.80
LogMethod · 0.80
NewFileReaderFunction · 0.70
StopMethod · 0.65
InitMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected