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

Function TestFileHeader_Encode

internal/utils/bfs/file_header_test.go:261–373  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

259}
260
261func TestFileHeader_Encode(t *testing.T) {
262 {
263 var header = &bfs.FileHeader{
264 Version: 1,
265 Status: 200,
266 ModifiedAt: fasttime.Now().Unix(),
267 ExpiresAt: fasttime.Now().Unix() + 3600,
268 BodySize: 1 << 20,
269 HeaderSize: 1 << 10,
270 BodyBlocks: []bfs.BlockInfo{
271 {
272 BFileOffsetFrom: 1 << 10,
273 BFileOffsetTo: 1 << 20,
274 },
275 },
276 }
277 data, err := header.Encode(bfs.Hash("123456"))
278 if err != nil {
279 t.Fatal(err)
280 }
281 jsonBytes, _ := json.Marshal(header)
282 t.Log(len(header.BodyBlocks), "blocks", len(data), "bytes", "json:", len(jsonBytes), "bytes")
283
284 _, _, _, err = bfs.DecodeMetaBlock(data)
285 if err != nil {
286 t.Fatal(err)
287 }
288 }
289
290 {
291 var header = &bfs.FileHeader{
292 Version: 1,
293 Status: 200,
294 BodyBlocks: []bfs.BlockInfo{},
295 }
296 var offset int64
297 for {
298 var end = offset + 16<<10
299 if end > 256<<10 {
300 break
301 }
302
303 header.BodyBlocks = append(header.BodyBlocks, bfs.BlockInfo{
304 BFileOffsetFrom: offset,
305 BFileOffsetTo: end,
306 })
307
308 offset = end
309 }
310 data, err := header.Encode(bfs.Hash("123456"))
311 if err != nil {
312 t.Fatal(err)
313 }
314 jsonBytes, _ := json.Marshal(header)
315 t.Log(len(header.BodyBlocks), "blocks", len(data), "bytes", "json:", len(jsonBytes), "bytes")
316 }
317
318 {

Callers

nothing calls this directly

Calls 6

NowFunction · 0.92
HashFunction · 0.92
DecodeMetaBlockFunction · 0.92
UnixMethod · 0.80
LogMethod · 0.80
EncodeMethod · 0.65

Tested by

no test coverage detected