Fixed TestGetFile unit test
Этот коммит содержится в:
@@ -152,7 +152,6 @@ func TestGetFile(t *testing.T) {
|
|||||||
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
||||||
|
|
||||||
if utils.Cfg.FileSettings.DriverName != "" {
|
if utils.Cfg.FileSettings.DriverName != "" {
|
||||||
|
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
part, err := writer.CreateFormFile("files", "test.png")
|
part, err := writer.CreateFormFile("files", "test.png")
|
||||||
@@ -204,9 +203,9 @@ func TestGetFile(t *testing.T) {
|
|||||||
if resp, downErr := Client.GetFileInfo(filenames[0]); downErr != nil {
|
if resp, downErr := Client.GetFileInfo(filenames[0]); downErr != nil {
|
||||||
t.Fatal(downErr)
|
t.Fatal(downErr)
|
||||||
} else {
|
} else {
|
||||||
m := resp.Data.(map[string]string)
|
info := resp.Data.(*model.FileInfo)
|
||||||
if len(m["size"]) == 0 {
|
if info.Size == 0 {
|
||||||
t.Fail()
|
t.Fatal("No file size returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -717,7 +717,7 @@ func (c *Client) GetFileInfo(url string) (*Result, *AppError) {
|
|||||||
return nil, AppErrorFromJson(rp.Body)
|
return nil, AppErrorFromJson(rp.Body)
|
||||||
} else {
|
} else {
|
||||||
return &Result{rp.Header.Get(HEADER_REQUEST_ID),
|
return &Result{rp.Header.Get(HEADER_REQUEST_ID),
|
||||||
rp.Header.Get(HEADER_ETAG_SERVER), MapFromJson(rp.Body)}, nil
|
rp.Header.Get(HEADER_ETAG_SERVER), FileInfoFromJson(rp.Body)}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"image/gif"
|
"image/gif"
|
||||||
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
@@ -58,3 +59,14 @@ func (info *FileInfo) ToJson() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FileInfoFromJson(data io.Reader) *FileInfo {
|
||||||
|
decoder := json.NewDecoder(data)
|
||||||
|
|
||||||
|
var info FileInfo
|
||||||
|
if err := decoder.Decode(&info); err != nil {
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return &info
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user