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

Function testObjectAnnotations

functional_tests.go:1845–1943  ·  view source on GitHub ↗

Tests {Put,Get,List,Remove}ObjectAnnotation APIs end to end. Servers that do not implement annotations are detected and skipped (logIgnored) rather than failed: a non-implementing server silently treats the ?annotation request as a plain object write, which is caught here via the parent ETag invaria

()

Source from the content-addressed store, hash-verified

1843// failed: a non-implementing server silently treats the ?annotation request as
1844// a plain object write, which is caught here via the parent ETag invariant.
1845func testObjectAnnotations() {
1846 startTime := time.Now()
1847 testName := getFuncName()
1848 function := "{Put,Get,List,Remove}ObjectAnnotation()"
1849 args := map[string]interface{}{}
1850
1851 c, err := NewClient(ClientConfig{})
1852 if err != nil {
1853 logError(testName, function, args, startTime, "", "MinIO client object creation failed", err)
1854 return
1855 }
1856
1857 bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-")
1858 objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "")
1859 args["bucketName"] = bucketName
1860 args["objectName"] = objectName
1861
1862 if err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"}); err != nil {
1863 logError(testName, function, args, startTime, "", "MakeBucket failed", err)
1864 return
1865 }
1866 defer cleanupBucket(bucketName, c)
1867
1868 const parentContent = "annotation-parent-content"
1869 ui, err := c.PutObject(context.Background(), bucketName, objectName, strings.NewReader(parentContent), int64(len(parentContent)), minio.PutObjectOptions{})
1870 if err != nil {
1871 logError(testName, function, args, startTime, "", "PutObject (parent) failed", err)
1872 return
1873 }
1874
1875 annName := "model.labels.json"
1876 annPayload := []byte(`{"label":"cat","score":0.98}`)
1877 args["annotationName"] = annName
1878
1879 _, err = c.PutObjectAnnotation(context.Background(), bucketName, objectName, annName, bytes.NewReader(annPayload), minio.PutObjectAnnotationOptions{})
1880 if err != nil {
1881 if isErrNotImplemented(err) {
1882 logIgnored(testName, function, args, startTime, "PutObjectAnnotation")
1883 return
1884 }
1885 logError(testName, function, args, startTime, "", "PutObjectAnnotation failed", err)
1886 return
1887 }
1888
1889 // On a server without annotation support the request falls through to a
1890 // regular PutObject, changing the parent ETag. Treat that as unsupported.
1891 st, err := c.StatObject(context.Background(), bucketName, objectName, minio.StatObjectOptions{})
1892 if err != nil {
1893 logError(testName, function, args, startTime, "", "StatObject failed", err)
1894 return
1895 }
1896 if st.ETag != ui.ETag {
1897 logIgnored(testName, function, args, startTime, "PutObjectAnnotation")
1898 return
1899 }
1900
1901 annReader, err := c.GetObjectAnnotation(context.Background(), bucketName, objectName, annName, minio.GetObjectAnnotationOptions{})
1902 if err != nil {

Callers 1

mainFunction · 0.85

Calls 15

MakeBucketMethod · 0.95
PutObjectMethod · 0.95
PutObjectAnnotationMethod · 0.95
StatObjectMethod · 0.95
GetObjectAnnotationMethod · 0.95
ListObjectAnnotationsMethod · 0.95
getFuncNameFunction · 0.85
NewClientFunction · 0.85
logErrorFunction · 0.85
cleanupBucketFunction · 0.85
isErrNotImplementedFunction · 0.85

Tested by

no test coverage detected