Add unit test for http fileloader

This commit is contained in:
Yujun Zhang
2020-02-27 21:05:37 +08:00
parent ff6250cdb4
commit 382425d974
2 changed files with 104 additions and 3 deletions

View File

@@ -89,6 +89,9 @@ type fileLoader struct {
// File system utilities.
fSys filesys.FileSystem
// Used to load from HTTP
http *http.Client
// Used to clone repositories.
cloner git.Cloner
@@ -296,9 +299,14 @@ func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
// else an error. Relative paths are taken relative
// to the root.
func (fl *fileLoader) Load(path string) ([]byte, error) {
if u, err := url.Parse(path); err == nil && strings.HasPrefix(u.Scheme, "http") {
client := &http.Client{}
resp, err := client.Get(path)
if u, err := url.Parse(path); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
var hc *http.Client
if fl.http != nil {
hc = fl.http
} else {
hc = &http.Client{}
}
resp, err := hc.Get(path)
if err != nil {
return nil, err
}