@@ -21,7 +21,11 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"math/rand"
24
+ "mime"
25
+ "net/http"
24
26
"net/url"
27
+ "reflect"
28
+ "strings"
25
29
"testing"
26
30
"time"
27
31
@@ -467,3 +471,74 @@ func TestFullObjectChecksum64(t *testing.T) {
467
471
})
468
472
}
469
473
}
474
+
475
+ func TestExtractObjMetadata (t * testing.T ) {
476
+ tests := []struct {
477
+ name string
478
+ header http.Header
479
+ want http.Header
480
+ }{
481
+ {
482
+ name : "Test with valid header" ,
483
+ header : http.Header {
484
+ "X-Minio-Meta-Test" : []string {"test" },
485
+ },
486
+ want : http.Header {
487
+ "X-Minio-Meta-Test" : []string {"test" },
488
+ },
489
+ },
490
+ {
491
+ name : "Test with valid header with QEncoding characters" ,
492
+ header : http.Header {
493
+ "X-Minio-Meta-Test" : []string {mime .QEncoding .Encode ("UTF-8" , "öha, das" )},
494
+ },
495
+ want : http.Header {
496
+ "X-Minio-Meta-Test" : []string {"öha, das" },
497
+ },
498
+ },
499
+ {
500
+ name : "Test with valid header with BEncoding characters" ,
501
+ header : http.Header {
502
+ "X-Minio-Meta-Test" : []string {mime .BEncoding .Encode ("UTF-8" , "öha, das" )},
503
+ },
504
+ want : http.Header {
505
+ "X-Minio-Meta-Test" : []string {"öha, das" },
506
+ },
507
+ },
508
+ {
509
+ name : "Test with valid header with multi-QEncoding characters" ,
510
+ header : http.Header {
511
+ "X-Minio-Meta-Test" : []string {mime .QEncoding .Encode ("UTF-8" , strings .Repeat ("öha, das" , 100 ))},
512
+ },
513
+ want : http.Header {
514
+ "X-Minio-Meta-Test" : []string {strings .Repeat ("öha, das" , 100 )},
515
+ },
516
+ },
517
+ {
518
+ name : "Test with valid header with multi-BEncoding characters" ,
519
+ header : http.Header {
520
+ "X-Minio-Meta-Test" : []string {mime .BEncoding .Encode ("UTF-8" , strings .Repeat ("öha, das" , 100 ))},
521
+ },
522
+ want : http.Header {
523
+ "X-Minio-Meta-Test" : []string {strings .Repeat ("öha, das" , 100 )},
524
+ },
525
+ },
526
+ {
527
+ name : "Test with valid header with multi-BEncoding characters" ,
528
+ header : http.Header {
529
+ "X-Minio-Meta-Test" : []string {mime .BEncoding .Encode ("UTF-8" , strings .Repeat ("öha, das" , 100 )), mime .BEncoding .Encode ("UTF-8" , strings .Repeat ("öha, das123" , 100 ))},
530
+ },
531
+ want : http.Header {
532
+ "X-Minio-Meta-Test" : []string {strings .Repeat ("öha, das" , 100 ), strings .Repeat ("öha, das123" , 100 )},
533
+ },
534
+ },
535
+ }
536
+ for _ , tt := range tests {
537
+ t .Run (tt .name , func (t * testing.T ) {
538
+ got := extractObjMetadata (tt .header )
539
+ if ! reflect .DeepEqual (got , tt .want ) {
540
+ t .Errorf ("extractObjMetadata() = %v, want %v" , got , tt .want )
541
+ }
542
+ })
543
+ }
544
+ }
0 commit comments