MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / TestMemoryReader_Body_Range

Function TestMemoryReader_Body_Range

internal/caches/reader_memory_test.go:41–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestMemoryReader_Body_Range(t *testing.T) {
42 item := &MemoryItem{
43 ExpiresAt: 0,
44 HeaderValue: nil,
45 BodyValue: []byte("0123456789"),
46 Status: 2000,
47 }
48 reader := NewMemoryReader(item)
49 buf := make([]byte, 6)
50 var err error
51 {
52 err = reader.ReadBodyRange(buf, 0, 0, func(n int) (goNext bool, err error) {
53 t.Log("[0, 0]", "body:", string(buf[:n]))
54 return true, nil
55 })
56 if err != nil {
57 t.Fatal(err)
58 }
59 }
60 {
61 err = reader.ReadBodyRange(buf, 7, 7, func(n int) (goNext bool, err error) {
62 t.Log("[7, 7]", "body:", string(buf[:n]))
63 return true, nil
64 })
65 if err != nil {
66 t.Fatal(err)
67 }
68 }
69 {
70 err = reader.ReadBodyRange(buf, 0, 10, func(n int) (goNext bool, err error) {
71 t.Log("[0, 10]", "body:", string(buf[:n]))
72 return true, nil
73 })
74 if err != nil {
75 t.Fatal(err)
76 }
77 }
78 {
79 err = reader.ReadBodyRange(buf, 3, 5, func(n int) (goNext bool, err error) {
80 t.Log("[3, 5]", "body:", string(buf[:n]))
81 return true, nil
82 })
83 if err != nil {
84 t.Fatal(err)
85 }
86 }
87 {
88 err = reader.ReadBodyRange(buf, -1, -3, func(n int) (goNext bool, err error) {
89 t.Log("[, -3]", "body:", string(buf[:n]))
90 return true, nil
91 })
92 if err != nil {
93 t.Fatal(err)
94 }
95 }
96 {
97 err = reader.ReadBodyRange(buf, 3, -1, func(n int) (goNext bool, err error) {
98 t.Log("[3, ]", "body:", string(buf[:n]))

Callers

nothing calls this directly

Calls 3

ReadBodyRangeMethod · 0.95
NewMemoryReaderFunction · 0.85
LogMethod · 0.80

Tested by

no test coverage detected