in testSuite/cmd/testfile.go [215:334]
func verifySingleFileUpload(testFileCmd TestFileCommand) {
fileInfo, err := os.Stat(testFileCmd.Object)
if err != nil {
fmt.Println("error opening the destination localFile on local disk ")
os.Exit(1)
}
localFile, err := os.Open(testFileCmd.Object)
if err != nil {
fmt.Println("error opening the localFile ", testFileCmd.Object)
}
fileClient, _ := file.NewClientWithNoCredential(testFileCmd.Subject, nil)
get, err := fileClient.DownloadStream(context.Background(), nil)
if err != nil {
fmt.Println("unable to get localFile properties ", err.Error())
os.Exit(1)
}
// reading all the bytes downloaded.
retryReader := get.NewRetryReader(context.Background(), &file.RetryReaderOptions{MaxRetries: 3})
defer retryReader.Close()
fileBytesDownloaded, err := io.ReadAll(retryReader)
if err != nil {
fmt.Println("error reading the byes from response and failed with error ", err.Error())
os.Exit(1)
}
if fileInfo.Size() == 0 {
// If the fileSize is 0 and the len of downloaded bytes is not 0
// validation fails
if len(fileBytesDownloaded) != 0 {
fmt.Printf("validation failed since the actual localFile size %d differs from the downloaded localFile size %d\n", fileInfo.Size(), len(fileBytesDownloaded))
os.Exit(1)
}
// If both the actual and downloaded localFile size is 0,
// validation is successful, no need to match the md5
os.Exit(0)
}
// memory mapping the resource on local path.
mmap, err := NewMMF(localFile, false, 0, fileInfo.Size())
if err != nil {
fmt.Println("error mapping the destination localFile: ", localFile, " localFile size: ", fileInfo.Size(), " Error: ", 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(fileBytesDownloaded)
if actualMd5 != expectedMd5 {
fmt.Println("the uploaded localFile's md5 doesn't matches the actual localFile's md5 for localFile ", testFileCmd.Object)
os.Exit(1)
}
if testFileCmd.CheckContentMD5 && len(get.ContentMD5) == 0 {
fmt.Println("ContentMD5 should not be empty")
os.Exit(1)
}
// verify the user given metadata supplied while uploading the localFile against the metadata actually present in the localFile
if !validateMetadata(testFileCmd.MetaData, get.Metadata) {
fmt.Println("meta data does not match between the actual and uploaded localFile.")
os.Exit(1)
}
// verify the content-type
expectedContentType := ""
if testFileCmd.NoGuessMimeType {
expectedContentType = testFileCmd.ContentType
} else {
expectedContentType = http.DetectContentType(mmap)
}
expectedContentType = strings.Split(expectedContentType, ";")[0]
if !validateString(expectedContentType, common.IffNotNil(get.ContentType, "")) {
str1 := fmt.Sprintf(" %s %s", expectedContentType, common.IffNotNil(get.ContentDisposition, ""))
fmt.Println(str1 + "mismatch content type between actual and user given localFile content type")
os.Exit(1)
}
//verify the content-encoding
if !validateString(testFileCmd.ContentEncoding, common.IffNotNil(get.ContentEncoding, "")) {
fmt.Println("mismatch content encoding between actual and user given localFile content encoding")
os.Exit(1)
}
if !validateString(testFileCmd.ContentDisposition, common.IffNotNil(get.ContentDisposition, "")) {
fmt.Println("mismatch content disposition between actual and user given value")
os.Exit(1)
}
if !validateString(testFileCmd.ContentLanguage, common.IffNotNil(get.ContentLanguage, "")) {
fmt.Println("mismatch content encoding between actual and user given value")
os.Exit(1)
}
if !validateString(testFileCmd.CacheControl, common.IffNotNil(get.CacheControl, "")) {
fmt.Println("mismatch cache control between actual and user given value")
os.Exit(1)
}
mmap.Unmap()
localFile.Close()
// verify the number of pageranges.
// this verifies the page-size and azcopy pagefile implementation.
if testFileCmd.VerifyBlockOrPageSize {
numberOfPages := int(testFileCmd.NumberOfBlocksOrPages)
resp, err := fileClient.GetRangeList(context.Background(), nil)
if err != nil {
fmt.Println("error getting the range list ", err.Error())
os.Exit(1)
}
if numberOfPages != (len(resp.Ranges)) {
fmt.Println("number of ranges uploaded is different from the number of expected to be uploaded")
os.Exit(1)
}
}
}