utils_test.go 981 字节
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())
}