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

Function TestCorePutObject

core_test.go:652–744  ·  view source on GitHub ↗

Test Core PutObject.

(t *testing.T)

Source from the content-addressed store, hash-verified

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