in testSuite/cmd/testblob.go [601:739]
func verifySingleAppendBlob(testBlobCmd TestBlobCommand) {
fileInfo, err := os.Stat(testBlobCmd.Object)
if err != nil {
fmt.Println("error opening the destination blob on local disk ")
os.Exit(1)
}
file, err := os.Open(testBlobCmd.Object)
if err != nil {
fmt.Println("error opening the file ", testBlobCmd.Object)
}
testCtx := context.WithValue(context.Background(), ste.ServiceAPIVersionOverride, defaultServiceApiVersion)
isAppend, err := verifyBlobType(testBlobCmd.Subject, testCtx, "AppendBlob")
if !isAppend || err != nil {
fmt.Println(err)
os.Exit(1)
}
appendBlobClient, err := appendblob.NewClientWithNoCredential(testBlobCmd.Subject, &appendblob.ClientOptions{
ClientOptions: azcore.ClientOptions{
Telemetry: policy.TelemetryOptions{ApplicationID: common.UserAgent},
Retry: policy.RetryOptions{
MaxRetries: ste.UploadMaxTries,
TryTimeout: 10 * time.Minute,
RetryDelay: ste.UploadRetryDelay,
MaxRetryDelay: ste.UploadMaxRetryDelay,
},
Transport: ste.NewAzcopyHTTPClient(0),
}})
if err != nil {
fmt.Printf("error creating append blob client. failed with error %s\n", err.Error())
os.Exit(1)
}
// get the blob properties and check the blob tier.
if testBlobCmd.BlobTier != "" {
blobProperties, err := appendBlobClient.GetProperties(testCtx, nil)
if err != nil {
fmt.Printf("error getting the properties of the blob. failed with error %s\n", err.Error())
os.Exit(1)
}
// If the blob tier does not match the expected blob tier.
if !strings.EqualFold(common.IffNotNil(blobProperties.AccessTier, ""), testBlobCmd.BlobTier) {
fmt.Printf("Access blob tier type %s does not match the expected %s tier type\n", common.IffNotNil(blobProperties.AccessTier, ""), testBlobCmd.BlobTier)
os.Exit(1)
}
}
get, err := appendBlobClient.DownloadStream(testCtx, nil)
if err != nil {
fmt.Println("unable to get blob properties ", err.Error())
os.Exit(1)
}
// reading all the bytes downloaded.
blobBytesDownloaded, err := io.ReadAll(get.Body)
if get.Body != nil {
get.Body.Close()
}
if err != nil {
fmt.Println("error reading the byes from response and failed with error ", err.Error())
os.Exit(1)
}
// verify the content-type
expectedContentType := ""
if testBlobCmd.NoGuessMimeType {
expectedContentType = testBlobCmd.ContentType
}
if len(blobBytesDownloaded) != 0 {
// memory mapping the resource on local path.
mmap, err := NewMMF(file, false, 0, fileInfo.Size())
if err != nil {
fmt.Println("error mapping the destination blob file ", err.Error())
os.Exit(1)
}
// calculating and verify the md5 of the resource
// both locally and on the container.
actualMd5 := md5.Sum(mmap)
expectedMd5 := md5.Sum(blobBytesDownloaded)
if actualMd5 != expectedMd5 {
fmt.Println("the uploaded blob's md5 doesn't matches the actual blob's md5 for blob ", testBlobCmd.Object)
os.Exit(1)
}
if !testBlobCmd.NoGuessMimeType {
expectedContentType = strings.Split(http.DetectContentType(mmap), ";")[0]
}
mmap.Unmap()
}
// verify the user given metadata supplied while uploading the blob against the metadata actually present in the blob
if !validateMetadata(testBlobCmd.Metadata, get.Metadata) {
fmt.Println("meta data does not match between the actual and uploaded blob.")
os.Exit(1)
}
if testBlobCmd.CheckContentType && !validateString(expectedContentType, common.IffNotNil(get.ContentType, "")) {
fmt.Printf(
"mismatch content type between actual and user given blob content type, expected %q, actually %q\n",
expectedContentType,
common.IffNotNil(get.ContentType, ""))
os.Exit(1)
}
//verify the content-encoding
if !validateString(testBlobCmd.ContentEncoding, common.IffNotNil(get.ContentEncoding, "")) {
fmt.Println("mismatch ContentEncoding between actual and user given blob")
os.Exit(1)
}
if !validateString(testBlobCmd.CacheControl, common.IffNotNil(get.CacheControl, "")) {
fmt.Println("mismatch CacheControl between actual and user given blob")
os.Exit(1)
}
if !validateString(testBlobCmd.ContentDisposition, common.IffNotNil(get.ContentDisposition, "")) {
fmt.Println("mismatch ContentDisposition between actual and user given blob")
os.Exit(1)
}
if !validateString(testBlobCmd.ContentLanguage, common.IffNotNil(get.ContentLanguage, "")) {
fmt.Println("mismatch ContentLanguage between actual and user given blob")
os.Exit(1)
}
if testBlobCmd.CheckContentMD5 && len(get.ContentMD5) == 0 {
fmt.Println("ContentMD5 should not be empty")
os.Exit(1)
}
file.Close()
}