utils_test.go
981 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package aliyun
import (
"bytes"
"net/url"
"testing"
)
func Test_GetFile(t *testing.T) {
io, err := GetFileFromUrl("http://mmm-opp-dev.fjmaimaimai.com/file/opp/image/20200106/1578297295_RxJscRHCzQmxeseTAEQXTH7A7ZK6z4Fz.jpg")
if err != nil {
t.Log(err)
return
}
var buf bytes.Buffer
n, _ := buf.ReadFrom(io)
t.Log("read from reader:", n)
}
func Test_FileUrl(t *testing.T) {
input := []struct {
Module string
Input string
Except string
}{
{
Module: "UrlParse",
Input: "http://mmm-opp-dev.fjmaimaimai.com/file/opp/image/20200106/1578297295_RxJscRHCzQmxeseTAEQXTH7A7ZK6z4Fz.jpg",
Except: "/file/opp/image/20200106/1578297295_RxJscRHCzQmxeseTAEQXTH7A7ZK6z4Fz.jpg",
},
}
urlIn := input[0]
urlRaw, err := url.Parse(urlIn.Input)
if err != nil {
t.Fatal(err)
}
if urlRaw.Path != urlIn.Except {
t.Fatal(urlIn.Module, "Input:", urlIn.Input, "Out:", urlRaw.Path, "Except:", urlIn.Except)
}
urlRaw.Scheme = "https"
//t.Log(urlRaw.String())
}