@@ -5,13 +5,15 @@ package cmd
55import (
66 "encoding/json"
77 "errors"
8+ "path/filepath"
9+ "strings"
10+ "testing"
11+
812 "github.com/qiniu/qshell/v2/cmd_test/test"
913 "github.com/qiniu/qshell/v2/iqshell/common/config"
1014 "github.com/qiniu/qshell/v2/iqshell/common/data"
15+ "github.com/qiniu/qshell/v2/iqshell/common/utils"
1116 "github.com/qiniu/qshell/v2/iqshell/storage/object/download/operations"
12- "path/filepath"
13- "strings"
14- "testing"
1517)
1618
1719func TestDownloadWithKeyFile (t * testing.T ) {
@@ -70,7 +72,7 @@ func TestDownloadFromBucket(t *testing.T) {
7072 Bucket : test .Bucket ,
7173 Prefix : "hello3,hello5,hello7" ,
7274 Suffixes : "" ,
73- IoHost : test .BucketDomain ,
75+ IoHost : utils . Endpoint ( false , test .BucketDomain ) ,
7476 Public : true ,
7577 CheckSize : true ,
7678 Referer : "" ,
@@ -111,11 +113,11 @@ func TestDownloadWithDomain(t *testing.T) {
111113 Bucket : test .Bucket ,
112114 Prefix : "hello3,hello5,hello7" ,
113115 Suffixes : "" ,
114- IoHost : test .BucketDomain ,
116+ IoHost : utils . Endpoint ( false , test .BucketDomain ) ,
115117 Public : true ,
116118 CheckSize : true ,
117119 Referer : "" ,
118- Domain : test .BucketDomain ,
120+ Domain : utils . Endpoint ( false , test .BucketDomain ) ,
119121 RecordRoot : "" ,
120122 },
121123 }
@@ -151,7 +153,7 @@ func TestDownloadNoBucket(t *testing.T) {
151153 Bucket : "" ,
152154 Prefix : "hello3,hello5,hello7" ,
153155 Suffixes : "" ,
154- IoHost : test .BucketDomain ,
156+ IoHost : utils . Endpoint ( false , test .BucketDomain ) ,
155157 Public : true ,
156158 CheckHash : true ,
157159 Referer : "" ,
@@ -438,7 +440,7 @@ func TestDownload2PublicWithDomain(t *testing.T) {
438440
439441 test .RunCmdWithError ("qdownload2" ,
440442 "--bucket" , test .Bucket ,
441- "--domain" , test .BucketDomain ,
443+ "--domain" , utils . Endpoint ( false , test .BucketDomain ) ,
442444 "--dest-dir" , destDir ,
443445 "--key-file" , keysFilePath ,
444446 "--log-file" , logPath ,
@@ -462,6 +464,42 @@ func TestDownload2PublicWithDomain(t *testing.T) {
462464 return
463465}
464466
467+ func TestDownload2PublicWithErrorDomain (t * testing.T ) {
468+ test .RemoveRootPath ()
469+
470+ keys := test .KeysString + "\n hello_10.json"
471+ keysFilePath , err := test .CreateFileWithContent ("download_keys.txt" , keys )
472+ if err != nil {
473+ t .Fatal ("create cdn config file error:" , err )
474+ }
475+
476+ rootPath , err := test .RootPath ()
477+ if err != nil {
478+ t .Fatal ("get root path error:" , err )
479+ }
480+
481+ destDir := filepath .Join (rootPath , "download2" )
482+
483+ errString , _ := test .RunCmdWithError ("qdownload2" ,
484+ "--bucket" , test .Bucket ,
485+ "--domain" , "error.qiniu.com" ,
486+ "--dest-dir" , destDir ,
487+ "--key-file" , keysFilePath ,
488+ "--log-level" , "debug" ,
489+ "--public" ,
490+ "-c" , "4" ,
491+ "-d" )
492+ if len (errString ) == 0 {
493+ t .Fatal ("should be error" )
494+ }
495+
496+ if test .FileCountInDir (destDir ) > 0 {
497+ t .Fatal ("no file should be download" )
498+ }
499+
500+ return
501+ }
502+
465503func TestDownload2Document (t * testing.T ) {
466504 test .TestDocument ("qdownload2" , t )
467505}
0 commit comments