diff --git a/cmd/jb/install.go b/cmd/jb/install.go index c3b22b1..a973af6 100644 --- a/cmd/jb/install.go +++ b/cmd/jb/install.go @@ -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 diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index 3c06d64..e3a359f 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -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 { diff --git a/cmd/jb/main.go b/cmd/jb/main.go index f7137f1..67366ec 100644 --- a/cmd/jb/main.go +++ b/cmd/jb/main.go @@ -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 } diff --git a/cmd/jb/main_test.go b/cmd/jb/main_test.go index 594264f..3a4007e 100644 --- a/cmd/jb/main_test.go +++ b/cmd/jb/main_test.go @@ -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)