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

Function testPutObjectPreconditionOnNonExistent

functional_tests.go:4047–4131  ·  view source on GitHub ↗

Test PutObject with preconditions on non-existent objects

()

Source from the content-addressed store, hash-verified

4045
4046// Test PutObject with preconditions on non-existent objects
4047func testPutObjectPreconditionOnNonExistent() {
4048 startTime := time.Now()
4049 testName := getFuncName()
4050 function := "PutObject(bucketName, objectName, reader, size, opts) with preconditions"
4051 args := map[string]interface{}{
4052 "bucketName": "",
4053 "objectName": "",
4054 "opts": "minio.PutObjectOptions{SetMatchETag/SetMatchETagExcept}",
4055 }
4056
4057 c, err := NewClient(ClientConfig{})
4058 if err != nil {
4059 logError(testName, function, args, startTime, "", "MinIO client object creation failed", err)
4060 return
4061 }
4062
4063 bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-")
4064 args["bucketName"] = bucketName
4065
4066 err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"})
4067 if err != nil {
4068 logError(testName, function, args, startTime, "", "MakeBucket failed", err)
4069 return
4070 }
4071
4072 defer cleanupBucket(bucketName, c)
4073
4074 // Test 1: PutObject with SetMatchETag on non-existent object should fail
4075 objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "test-object-")
4076 args["objectName"] = objectName
4077
4078 data := bytes.NewReader([]byte("test data"))
4079
4080 opts := minio.PutObjectOptions{}
4081 opts.SetMatchETag("some-etag")
4082
4083 _, err = c.PutObject(context.Background(), bucketName, objectName, data, int64(data.Len()), opts)
4084 if err == nil {
4085 logError(testName, function, args, startTime, "", "PutObject with SetMatchETag on non-existent object should have failed", nil)
4086 return
4087 }
4088
4089 errResp := minio.ToErrorResponse(err)
4090 if errResp.Code != "NoSuchKey" {
4091 logError(testName, function, args, startTime, "", fmt.Sprintf("Expected NoSuchKey error (AWS standard for non-existent objects), got %s", errResp.Code), err)
4092 return
4093 }
4094
4095 // Test 2: PutObject with SetMatchETagExcept (If-None-Match) on non-existent object should succeed
4096 objectName2 := randString(60, rand.NewSource(time.Now().UnixNano()), "test-object2-")
4097 args["objectName"] = objectName2
4098
4099 data2 := bytes.NewReader([]byte("test data 2"))
4100 opts2 := minio.PutObjectOptions{}
4101 opts2.SetMatchETagExcept("some-etag")
4102
4103 _, err = c.PutObject(context.Background(), bucketName, objectName2, data2, int64(data2.Len()), opts2)
4104 if err != nil {

Callers 1

mainFunction · 0.85

Calls 11

MakeBucketMethod · 0.95
SetMatchETagMethod · 0.95
PutObjectMethod · 0.95
SetMatchETagExceptMethod · 0.95
getFuncNameFunction · 0.85
NewClientFunction · 0.85
logErrorFunction · 0.85
cleanupBucketFunction · 0.85
logSuccessFunction · 0.85
LenMethod · 0.80
randStringFunction · 0.70

Tested by

no test coverage detected