For local dependencies check if abs path exists

This commit is contained in:
Matthias Loibl 2019-08-12 11:50:56 +02:00
parent e655fcaf60
commit 6ed6c3f3ec
No known key found for this signature in database
GPG key ID: 78A796CA74CA38BA
4 changed files with 11 additions and 8 deletions

View file

@ -46,7 +46,7 @@ func installCommand(dir, jsonnetHome string, paths ...string) int {
if len(paths) > 0 {
for _, path := range paths {
newDep := parseDependency(path)
newDep := parseDependency(dir, path)
if newDep == nil {
kingpin.Errorf("ignoring unrecognized path: %s", path)
continue

View file

@ -49,8 +49,8 @@ func TestInstallCommand(t *testing.T) {
Name: "Relative",
URLs: []string{"test/jsonnet/foobar"},
ExpectedCode: 0,
ExpectedJsonnetFile: []byte(`{"dependencies":null}`),
ExpectedJsonnetLockFile: []byte(`{"dependencies":null}`),
ExpectedJsonnetFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
ExpectedJsonnetLockFile: []byte(`{"dependencies": [{"name": "foobar", "source": {"local": {"directory": "test/jsonnet/foobar"}}, "version": ""}]}`),
},
}
@ -81,6 +81,8 @@ func TestInstallCommand(t *testing.T) {
}
func jsonnetFileContent(t *testing.T, filename string, content []byte) {
t.Helper()
bytes, err := ioutil.ReadFile(filename)
assert.NoError(t, err)
if eq := assert.JSONEq(t, string(content), string(bytes)); !eq {

View file

@ -93,7 +93,7 @@ func Main() int {
return 0
}
func parseDependency(path string) *spec.Dependency {
func parseDependency(dir, path string) *spec.Dependency {
if d := parseGitSSHDependency(path); d != nil {
return d
}
@ -102,7 +102,7 @@ func parseDependency(path string) *spec.Dependency {
return d
}
if d := parseLocalDependency(path); d != nil {
if d := parseLocalDependency(dir, path); d != nil {
return d
}
@ -211,7 +211,7 @@ func parseGithubDependency(p string) *spec.Dependency {
}
}
func parseLocalDependency(p string) *spec.Dependency {
func parseLocalDependency(dir, p string) *spec.Dependency {
if p == "" {
return nil
}
@ -223,8 +223,9 @@ func parseLocalDependency(p string) *spec.Dependency {
}
clean := filepath.Clean(p)
abs := filepath.Join(dir, clean)
info, err := os.Stat(clean)
info, err := os.Stat(abs)
if err != nil {
return nil
}

View file

@ -89,7 +89,7 @@ func TestParseDependency(t *testing.T) {
}
for _, tt := range tests {
_ = t.Run(tt.name, func(t *testing.T) {
dependency := parseDependency(tt.path)
dependency := parseDependency("", tt.path)
if tt.path == "" {
assert.Nil(t, dependency)