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

Function TestPreHash

internal/stream/stream_test.go:97–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestPreHash(t *testing.T) {
98 buf := []byte("github.com/OpenListTeam/OpenList")
99 f := &stream.FileStream{
100 Obj: &model.Object{
101 Size: int64(len(buf)),
102 },
103 Reader: io.NopCloser(bytes.NewReader(buf)),
104 }
105 prevAutoMemoryLimit := conf.AutoMemoryLimit
106 prevMaxBlockLimit := conf.MaxBlockLimit
107 t.Cleanup(func() {
108 conf.AutoMemoryLimit = prevAutoMemoryLimit
109 conf.MaxBlockLimit = prevMaxBlockLimit
110 })
111 conf.AutoMemoryLimit = 0
112 conf.MaxBlockLimit = 15
113
114 const hashSize int64 = 20
115 reader, _ := f.RangeRead(http_range.Range{Start: 0, Length: hashSize})
116 preHash, _ := utils.HashReader(utils.SHA1, reader)
117 if preHash == "" {
118 t.Error("preHash is empty")
119 }
120 tmpF, fullHash, _ := stream.CacheFullAndHash(f, nil, utils.SHA1)
121 fmt.Println(fullHash)
122 fileFullHash, _ := utils.HashFile(utils.SHA1, tmpF)
123 fmt.Println(fileFullHash)
124 if fullHash != fileFullHash {
125 t.Errorf("fullHash and fileFullHash should match: fullHash=%s fileFullHash=%s", fullHash, fileFullHash)
126 }
127}
128
129func TestStreamSectionReader(t *testing.T) {
130 buf := make([]byte, 8<<10)

Callers

nothing calls this directly

Calls 5

RangeReadMethod · 0.95
HashReaderFunction · 0.92
CacheFullAndHashFunction · 0.92
HashFileFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected