How to use testFileDownload method of main Package

Best Selenoid code snippet using main.testFileDownload

apitest.go

Source:apitest.go Github

copy

Full Screen

...40 check(err)41 b := testBucketCreate(b2)42 // Test basic file operations43 f, data := testFileUpload(b)44 testFileDownload(b, f, data)45 testFileRangeDownload(b, f, data)46 testFileDelete(b, f)47 // Test file listing calls48 files := uploadFiles(b)49 testListFiles(b, files)50 testListDirectories(b, files)51 deleteFiles(b, files)52 testBucketDelete(b)53}54func testBucketCreate(b2 *backblaze.B2) *backblaze.Bucket {55 // Get Test bucket56 if opts.Bucket == "" {57 opts.Bucket = "test-bucket-" + randSeq(10)58 }59 log.Printf("Testing with bucket %s", opts.Bucket)60 b, err := b2.Bucket(opts.Bucket)61 check(err)62 if b != nil {63 log.Fatal("Testing bucket already exists")64 }65 b, err = b2.CreateBucket(opts.Bucket, backblaze.AllPrivate)66 check(err)67 log.Print("Bucket created")68 return b69}70func testBucketDelete(b *backblaze.Bucket) {71 check(b.Delete())72 log.Print("Bucket deleted")73}74func testFileUpload(b *backblaze.Bucket) (*backblaze.File, []byte) {75 fileData := randBytes(1024 * 1024)76 f, err := b.UploadFile("test_file", nil, bytes.NewBuffer(fileData))77 check(err)78 log.Print("File uploaded")79 return f, fileData80}81func testFileDownload(b *backblaze.Bucket, f *backblaze.File, data []byte) {82 f, reader, err := b.DownloadFileByName(f.Name)83 check(err)84 body, err := ioutil.ReadAll(reader)85 check(err)86 if !bytes.Equal(body, data) {87 log.Fatal("Downloaded file content does not match upload")88 }89 log.Print("File downloaded")90}91func testFileRangeDownload(b *backblaze.Bucket, f *backblaze.File, data []byte) {92 f, reader, err := b.DownloadFileRangeByName(f.Name, &backblaze.FileRange{Start: 100, End: 2000})93 check(err)94 body, err := ioutil.ReadAll(reader)95 check(err)...

Full Screen

Full Screen

drive.go

Source:drive.go Github

copy

Full Screen

...19var driveService = drivev1.NewService(configs.TestConfig(core.DomainFeiShu))20func main() {21 testFileUploadAll()22 testMediaBatchGetTmpDownloadURLs()23 testFileDownload()24}25func createRandomFileData(size int64) []byte {26 randomData := make([]byte, size)27 io.ReadFull(rand.Reader, randomData)28 return randomData29}30func testFileUploadAll() {31 coreCtx := core.WrapContext(context.Background())32 reqCall := driveService.Files.UploadAll(coreCtx, request.SetUserAccessToken("[user_access_token]"))33 reqCall.SetParentType("explorer")34 reqCall.SetParentNode("[folder_token]")35 reqCall.SetFileName(fmt.Sprintf("[file_name]"))36 reqCall.SetSize(1024)37 fileContent := createRandomFileData(1024)38 reqCall.SetChecksum(fmt.Sprintf("%d", adler32.Checksum(fileContent)))39 file := request.NewFile()40 file.SetContent(fileContent)41 reqCall.SetFile(file)42 result, err := reqCall.Do()43 fmt.Printf("request_id:%s", coreCtx.GetRequestID())44 fmt.Printf("http status code:%d", coreCtx.GetHTTPStatusCode())45 if err != nil {46 e := err.(*response.Error)47 fmt.Println(tools.Prettify(e))48 return49 }50 fmt.Printf("reault:%s", tools.Prettify(result))51 if len(result.FileToken) == 0 {52 fmt.Printf("file token is empty")53 return54 }55}56func testMediaBatchGetTmpDownloadURLs() {57 coreCtx := core.WrapContext(context.Background())58 userAccessTokenOptFn := request.SetUserAccessToken("[user_access_token]")59 reqCall := driveService.Medias.BatchGetTmpDownloadUrl(coreCtx, userAccessTokenOptFn)60 reqCall.SetFileTokens([]string{"[file_token]"}...)61 result, err := reqCall.Do()62 fmt.Printf("request_id:%s", coreCtx.GetRequestID())63 fmt.Printf("http status code:%d", coreCtx.GetHTTPStatusCode())64 if err != nil {65 e := err.(*response.Error)66 fmt.Println(tools.Prettify(e))67 return68 }69 fmt.Printf("reault:%s", tools.Prettify(result))70 if len(result.TmpDownloadUrls) == 0 {71 fmt.Printf("TmpDownloadUrls len invalid")72 return73 }74}75func testFileDownload() {76 coreCtx := core.WrapContext(context.Background())77 reqCall := driveService.Files.Download(coreCtx, request.SetUserAccessToken("[user_access_token]"))78 reqCall.SetFileToken("[file_token]")79 fileContent := bytes.NewBuffer(nil)80 reqCall.SetResponseStream(fileContent)81 _, err := reqCall.Do()82 fmt.Printf("request_id:%s", coreCtx.GetRequestID())83 fmt.Printf("http status code:%d", coreCtx.GetHTTPStatusCode())84 if err != nil {85 e := err.(*response.Error)86 fmt.Printf(tools.Prettify(e))87 return88 }89}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenoid automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful