Merge pull request #287 from emosbaugh/fix-gopath-isrepourl

Fix loader loader when run from gopath
This commit is contained in:
k8s-ci-robot
2018-08-23 15:08:25 -07:00
committed by GitHub
3 changed files with 67 additions and 2 deletions

View File

@@ -75,7 +75,11 @@ func newGithubLoader(repoUrl string, fs fs.FileSystem) (*githubLoader, error) {
// isRepoUrl checks if a string is a repo Url
func isRepoUrl(s string) bool {
return strings.Contains(s, ".com") || strings.Contains(s, ".org") || strings.Contains(s, "https://")
if strings.HasPrefix(s, "https://") {
return true
}
host := strings.SplitN(s, "/", 2)[0]
return strings.Contains(host, ".com") || strings.Contains(host, ".org")
}
// Checkout clones a github repo with specified commit/tag/branch

View File

@@ -0,0 +1,56 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package loader
import (
"testing"
)
func TestIsRepoURL(t *testing.T) {
testcases := []struct {
input string
expected bool
}{
{
input: "https://github.com/org/repo",
expected: true,
},
{
input: "github.com/org/repo",
expected: true,
},
{
input: "/github.com/org/repo",
expected: false,
},
{
input: "/abs/path/to/file",
expected: false,
},
{
input: "../relative",
expected: false,
},
}
for _, tc := range testcases {
actual := isRepoUrl(tc.input)
if actual != tc.expected {
t.Errorf("unexpected error: unexpected result %t for input %s", actual, tc.input)
}
}
}

View File

@@ -43,7 +43,7 @@ func NewLoader(target, r string, fSys fs.FileSystem) (Loader, error) {
return nil, fmt.Errorf("Not valid path: root='%s', loc='%s'\n", r, target)
}
if isRepoUrl(target) {
if !isLocalTarget(target, fSys) && isRepoUrl(target) {
return newGithubLoader(target, fSys)
}
@@ -73,3 +73,8 @@ func isValidLoaderPath(target, root string) bool {
func isRootLoaderPath(root string) bool {
return root == ""
}
// isLocalTarget checks if a file exists in the filesystem
func isLocalTarget(s string, fs fs.FileSystem) bool {
return fs.Exists(s)
}