Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huangnauh committed Oct 29, 2024
1 parent 9fa7c61 commit bebce53
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: golangci-lint command line arguments.
version: v1.47.3
version: latest
args:
# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/upyun/go-sdk/v3

go 1.13
go 1.17
4 changes: 2 additions & 2 deletions upyun/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ func checkResponse(res *http.Response) error {
uerr.StatusCode = res.StatusCode
uerr.Header = res.Header
defer res.Body.Close()
slurp, err := ioutil.ReadAll(res.Body)
slurp, err := io.ReadAll(res.Body)
if err != nil {
return uerr
}
Expand Down
3 changes: 1 addition & 2 deletions upyun/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
Expand Down Expand Up @@ -91,7 +90,7 @@ func (up *UpYun) FormUpload(config *FormUploadConfig) (*FormUploadResp, error) {
return nil, err
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
resp.Body.Close()

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions upyun/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (up *UpYun) doProcessRequest(method, uri string,
return errorOperation("process", err)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return errorOperation("process read body", err)
Expand Down Expand Up @@ -215,7 +215,7 @@ func (up *UpYun) doSyncProcessRequest(method, uri string, payload string) (map[s
return nil, errorOperation("sync process", err)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions upyun/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package upyun

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"path"
"testing"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestNagaResult(t *testing.T) {
Equal(t, len(res), 2)
}

//由于是异步操作,不能确保文件已存在
// 由于是异步操作,不能确保文件已存在
func TestImgaudit(t *testing.T) {
task := map[string]interface{}{
"url": JPG_URL,
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestImgaudit(t *testing.T) {

}

//由于是异步操作,不能确保文件已存在
// 由于是异步操作,不能确保文件已存在
func TestVideoaudit(t *testing.T) {
task := map[string]interface{}{
"url": MP4_URL,
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestFaceDetect(t *testing.T) {
resp, err := http.Get(FACE_URL + "!/face/detection")
Nil(t, err)
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
Nil(t, err)
if err != nil {
var result map[string]interface{}
Expand Down
4 changes: 2 additions & 2 deletions upyun/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package upyun

import (
"encoding/json"
"io/ioutil"
"io"
URL "net/url"
"strings"
"time"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (up *UpYun) Purge(urls []string) (fails []string, err error) {
}
defer resp.Body.Close()

content, err := ioutil.ReadAll(resp.Body)
content, err := io.ReadAll(resp.Body)
if err != nil {
return fails, errorOperation("purge read body", err)
}
Expand Down
20 changes: 11 additions & 9 deletions upyun/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -79,7 +78,7 @@ type GetRequestConfig struct {
Headers map[string]string
}

type ProxyReader func(size, offset int64, r io.Reader) io.Reader
type ProxyReader func(offset int64, r io.Reader) io.Reader

// PutObjectConfig provides a configuration to Put method.
type PutObjectConfig struct {
Expand Down Expand Up @@ -532,7 +531,7 @@ func (up *UpYun) ListMultipartUploads(config *ListMultipartConfig) (*ListMultipa
return nil, errorOperation("list multipart", err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errorOperation("list multipart read body", err)
}
Expand Down Expand Up @@ -563,7 +562,7 @@ func (up *UpYun) ListMultipartParts(intiResult *InitMultipartUploadResult, confi
return nil, errorOperation("list multipart parts", err)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errorOperation("list multipart parts read body", err)
}
Expand Down Expand Up @@ -688,7 +687,7 @@ func (up *UpYun) List(config *GetObjectsConfig) error {
return errorOperation("list", err)
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return errorOperation("list read body", err)
Expand Down Expand Up @@ -796,7 +795,7 @@ func (up *UpYun) ListObjects(config *ListObjectsConfig) (fileInfos []*FileInfo,
}

// 读取列表
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, "", errorOperation("list read body", err)
Expand Down Expand Up @@ -898,7 +897,7 @@ func (up *UpYun) doRESTRequest(config *restReqConfig) (*http.Response, error) {
}

if config.closeBody {
io.Copy(ioutil.Discard, resp.Body)
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}

Expand All @@ -914,16 +913,19 @@ type BreakPointConfig struct {
LastTime time.Time
}

func (up *UpYun) resumeUploadPart(config *PutObjectConfig, breakpoint *BreakPointConfig, f io.Reader, fileInfo fs.FileInfo) (*BreakPointConfig, error) {
func (up *UpYun) resumeUploadPart(config *PutObjectConfig, breakpoint *BreakPointConfig, f io.ReadSeeker, fileInfo fs.FileInfo) (*BreakPointConfig, error) {
fsize := fileInfo.Size()
partID := breakpoint.PartID
curSize, partSize := int64(partID)*breakpoint.PartSize, breakpoint.PartSize
bytesLeft := fsize - curSize
ch := make(chan *Chunk, 1)
var err error
if curSize > 0 {
f.Seek(curSize, 0)
}
var reader io.Reader
if config.ProxyReader != nil {
reader = config.ProxyReader(fsize, curSize, f)
reader = config.ProxyReader(curSize, f)
} else {
reader = f
}
Expand Down
Loading

0 comments on commit bebce53

Please sign in to comment.