fix: allow other dirs than vendor (#80)

This commit is contained in:
Hang Xie 2020-02-08 05:46:51 -08:00 committed by GitHub
parent 0ba0ff5522
commit 1d729c9517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 6 deletions

View file

@ -32,6 +32,18 @@ import (
const initContents = `{"dependencies": [], "legacyImports": true}`
func TestInstallCommand(t *testing.T) {
testInstallCommandWithJsonnetHome(t, "vendor")
}
func TestInstallCommandCustomJsonnetHome(t *testing.T) {
testInstallCommandWithJsonnetHome(t, "custom-vendor-dir")
}
func TestInstallCommandDeepCustomJsonnetHome(t *testing.T) {
testInstallCommandWithJsonnetHome(t, "custom/vendor/dir")
}
func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
testcases := []struct {
Name string
URIs []string
@ -65,7 +77,7 @@ func TestInstallCommand(t *testing.T) {
cleanup := func() {
_ = os.Remove(jsonnetfile.File)
_ = os.Remove(jsonnetfile.LockFile)
_ = os.RemoveAll("vendor")
_ = os.RemoveAll(jsonnetHome)
_ = os.RemoveAll("jsonnet")
}
@ -81,7 +93,7 @@ func TestInstallCommand(t *testing.T) {
jsonnetFileContent(t, jsonnetfile.File, []byte(initContents))
// install something, check it writes only if required, etc.
installCommand("", "vendor", tc.URIs)
installCommand("", jsonnetHome, tc.URIs)
jsonnetFileContent(t, jsonnetfile.File, tc.ExpectedJsonnetFile)
if tc.ExpectedJsonnetLockFile != nil {
jsonnetFileContent(t, jsonnetfile.LockFile, tc.ExpectedJsonnetLockFile)

View file

@ -17,6 +17,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"github.com/fatih/color"
"github.com/pkg/errors"
@ -67,6 +68,8 @@ func Main() int {
return 1
}
cfg.JsonnetHome = filepath.Clean(cfg.JsonnetHome)
switch command {
case initCmd.FullCommand():
return initCommand(workdir)