mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 16:10:04 +01:00
For local dependencies check if abs path exists
This commit is contained in:
parent
e655fcaf60
commit
6ed6c3f3ec
4 changed files with 11 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue