MCPcopy
hub / github.com/minio/minio-go / TestFullObjectChecksum64

Function TestFullObjectChecksum64

utils_test.go:437–475  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

435}
436
437func TestFullObjectChecksum64(t *testing.T) {
438 tests := []ChecksumType{
439 ChecksumCRC32,
440 ChecksumCRC32C,
441 ChecksumCRC64NVME,
442 }
443 for _, cs := range tests {
444 t.Run(cs.String(), func(t *testing.T) {
445 b := make([]byte, 1024000)
446 rng := rand.New(rand.NewSource(time.Now().UnixNano()))
447 rng.Read(b)
448 sum := cs.EncodeToString
449 want := sum(b)
450 var parts []ObjectPart
451 for len(b) > 0 {
452 sz := rng.Intn(len(b) / 2)
453 if len(b)-sz < 1024 {
454 sz = len(b)
455 }
456 switch cs {
457 case ChecksumCRC32:
458 parts = append(parts, ObjectPart{PartNumber: len(parts) + 1, ChecksumCRC32: cs.EncodeToString(b[:sz]), Size: int64(sz)})
459 case ChecksumCRC32C:
460 parts = append(parts, ObjectPart{PartNumber: len(parts) + 1, ChecksumCRC32C: cs.EncodeToString(b[:sz]), Size: int64(sz)})
461 case ChecksumCRC64NVME:
462 parts = append(parts, ObjectPart{PartNumber: len(parts) + 1, ChecksumCRC64NVME: cs.EncodeToString(b[:sz]), Size: int64(sz)})
463 }
464 b = b[sz:]
465 }
466 gotCRC, err := cs.FullObjectChecksum(parts)
467 if err != nil {
468 t.Fatal(err)
469 }
470 if gotCRC.Encoded() != want {
471 t.Errorf("Checksum %v does not match the expected CRC got:%s want:%s", cs.String(), gotCRC.Encoded(), want)
472 }
473 })
474 }
475}
476
477func TestExtractObjMetadata(t *testing.T) {
478 tests := []struct {

Callers

nothing calls this directly

Calls 5

EncodeToStringMethod · 0.80
FullObjectChecksumMethod · 0.80
EncodedMethod · 0.80
StringMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected