@@ -2,16 +2,13 @@ package export
2
2
3
3
import (
4
4
"context"
5
- "encoding/xml"
6
5
"flag"
7
- "fmt"
8
6
"io"
9
7
"net/http"
10
8
"os"
11
9
"testing"
12
10
"time"
13
11
14
- "github.com/go-resty/resty/v2"
15
12
"github.com/shiyuhang0/serverless-scene-test/config"
16
13
"github.com/shiyuhang0/serverless-scene-test/util"
17
14
"github.com/stretchr/testify/assert"
@@ -59,7 +56,7 @@ func TestExportToLocalAndDownload(t *testing.T) {
59
56
t .Log ("start to download files" )
60
57
for _ , exportFile := range exportFilesRes .Files {
61
58
// download file
62
- downloadRes , err := GetResponse (* exportFile .Url )
59
+ downloadRes , err := util . GetResponse (* exportFile .Url )
63
60
if err != nil {
64
61
t .Fatal (err )
65
62
}
@@ -378,34 +375,3 @@ func CreateExport(ctx context.Context, c *export.APIClient, clusterId string, bo
378
375
res , h , err := r .Execute ()
379
376
return res , util .ParseError (err , h )
380
377
}
381
-
382
- func GetResponse (url string ) (* http.Response , error ) {
383
- httpClient := resty .New ()
384
- resp , err := httpClient .GetClient ().Get (url )
385
- if err != nil {
386
- return nil , err
387
- }
388
- if resp .StatusCode != http .StatusOK {
389
- // read the body to get the error message
390
- body , err := io .ReadAll (resp .Body )
391
- resp .Body .Close ()
392
- if err != nil {
393
- return nil , fmt .Errorf ("receiving status of %d" , resp .StatusCode )
394
- }
395
- type AwsError struct {
396
- Code string `xml:"Code"`
397
- Message string `xml:"Message"`
398
- }
399
- v := AwsError {}
400
- err = xml .Unmarshal (body , & v )
401
- if err != nil {
402
- return nil , fmt .Errorf ("receiving status of %d" , resp .StatusCode )
403
- }
404
- return nil , fmt .Errorf ("receiving status of %d. code: %s, message: %s" , resp .StatusCode , v .Code , v .Message )
405
- }
406
- if resp .ContentLength <= 0 {
407
- resp .Body .Close ()
408
- return nil , fmt .Errorf ("file is empty" )
409
- }
410
- return resp , nil
411
- }
0 commit comments