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

Function testGetObjectModified

functional_tests.go:8290–8366  ·  view source on GitHub ↗

Test for validating GetObject Reader* methods functioning when the object is modified in the object store.

()

Source from the content-addressed store, hash-verified

8288// Test for validating GetObject Reader* methods functioning when the
8289// object is modified in the object store.
8290func testGetObjectModified() {
8291 // initialize logging params
8292 startTime := time.Now()
8293 testName := getFuncName()
8294 function := "GetObject(bucketName, objectName)"
8295 args := map[string]interface{}{}
8296
8297 c, err := NewClient(ClientConfig{})
8298 if err != nil {
8299 logError(testName, function, args, startTime, "", "MinIO client object creation failed", err)
8300 return
8301 }
8302
8303 // Make a new bucket.
8304 bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-")
8305 args["bucketName"] = bucketName
8306
8307 err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"})
8308 if err != nil {
8309 logError(testName, function, args, startTime, "", "MakeBucket failed", err)
8310 return
8311 }
8312
8313 defer cleanupBucket(bucketName, c)
8314
8315 // Upload an object.
8316 objectName := "myobject"
8317 args["objectName"] = objectName
8318 content := "helloworld"
8319 _, err = c.PutObject(context.Background(), bucketName, objectName, strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType: "application/text"})
8320 if err != nil {
8321 logError(testName, function, args, startTime, "", "Failed to upload "+objectName+", to bucket "+bucketName, err)
8322 return
8323 }
8324
8325 defer c.RemoveObject(context.Background(), bucketName, objectName, minio.RemoveObjectOptions{})
8326
8327 reader, err := c.GetObject(context.Background(), bucketName, objectName, minio.GetObjectOptions{})
8328 if err != nil {
8329 logError(testName, function, args, startTime, "", "Failed to GetObject "+objectName+", from bucket "+bucketName, err)
8330 return
8331 }
8332 defer reader.Close()
8333
8334 // Read a few bytes of the object.
8335 b := make([]byte, 5)
8336 n, err := reader.ReadAt(b, 0)
8337 if err != nil {
8338 logError(testName, function, args, startTime, "", "Failed to read object "+objectName+", from bucket "+bucketName+" at an offset", err)
8339 return
8340 }
8341
8342 // Upload different contents to the same object while object is being read.
8343 newContent := "goodbyeworld"
8344 _, err = c.PutObject(context.Background(), bucketName, objectName, strings.NewReader(newContent), int64(len(newContent)), minio.PutObjectOptions{ContentType: "application/text"})
8345 if err != nil {
8346 logError(testName, function, args, startTime, "", "Failed to upload "+objectName+", to bucket "+bucketName, err)
8347 return

Callers 1

mainFunction · 0.85

Calls 14

MakeBucketMethod · 0.95
PutObjectMethod · 0.95
RemoveObjectMethod · 0.95
GetObjectMethod · 0.95
getFuncNameFunction · 0.85
NewClientFunction · 0.85
logErrorFunction · 0.85
cleanupBucketFunction · 0.85
logSuccessFunction · 0.85
ReadAtMethod · 0.80
StatMethod · 0.80
randStringFunction · 0.70

Tested by

no test coverage detected