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

Function TestCorePutObject

core_test.go:657–749  ·  view source on GitHub ↗

Test Core PutObject.

(t *testing.T)

Source from the content-addressed store, hash-verified

655
656// Test Core PutObject.
657func TestCorePutObject(t *testing.T) {
658 if os.Getenv(serverEndpoint) == "" {
659 t.Skip("SERVER_ENDPOINT not set")
660 }
661 if testing.Short() {
662 t.Skip("skipping functional tests for short runs")
663 }
664
665 // Instantiate new minio client object.
666 c, err := NewCore(
667 os.Getenv(serverEndpoint),
668 &Options{
669 Creds: credentials.NewStaticV4(os.Getenv(accessKey), os.Getenv(secretKey), ""),
670 Secure: mustParseBool(os.Getenv(enableSecurity)),
671 })
672 if err != nil {
673 t.Fatal("Error:", err)
674 }
675
676 // Enable tracing, write to stderr.
677 // c.TraceOn(os.Stderr)
678
679 // Set user agent.
680 c.SetAppInfo("MinIO-go-FunctionalTest", "0.1.0")
681
682 // Generate a new random bucket name.
683 bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test")
684
685 // Make a new bucket.
686 err = c.MakeBucket(context.Background(), bucketName, MakeBucketOptions{Region: "us-east-1"})
687 if err != nil {
688 t.Fatal("Error:", err, bucketName)
689 }
690
691 buf := bytes.Repeat([]byte("a"), 32*1024)
692
693 // Save the data
694 objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "")
695 // Object content type
696 objectContentType := "binary/octet-stream"
697 metadata := make(map[string]string)
698 metadata["Content-Type"] = objectContentType
699 putopts := PutObjectOptions{
700 UserMetadata: metadata,
701 }
702 _, err = c.PutObject(context.Background(), bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), "1B2M2Y8AsgTpgAmY7PhCfg==", "", putopts)
703 if err == nil {
704 t.Fatal("Error expected: error, got: nil(success)")
705 }
706
707 _, err = c.PutObject(context.Background(), bucketName, objectName, bytes.NewReader(buf), int64(len(buf)), "", "", putopts)
708 if err != nil {
709 t.Fatal("Error:", err, bucketName, objectName)
710 }
711
712 // Read the data back
713 r, err := c.Client.GetObject(context.Background(), bucketName, objectName, GetObjectOptions{})
714 if err != nil {

Callers

nothing calls this directly

Calls 12

PutObjectMethod · 0.95
NewStaticV4Function · 0.92
NewCoreFunction · 0.85
SetAppInfoMethod · 0.80
MakeBucketMethod · 0.80
StatMethod · 0.80
RemoveObjectMethod · 0.80
RemoveBucketMethod · 0.80
mustParseBoolFunction · 0.70
randStringFunction · 0.70
GetObjectMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected