fix(init): ensure shims call namespaced which command

This commit is contained in:
Marc 2024-01-28 14:35:31 -05:00
parent 4b6a996e1d
commit 1b87b6fa1e
Signed by: marc
GPG key ID: 048E042F22B5DC79
2 changed files with 30 additions and 1 deletions

View file

@ -21,7 +21,7 @@ var SHIMS = []string{
const DEFAULT_PERMISSION = 0775 const DEFAULT_PERMISSION = 0775
func writeShim(shimPath string) error { func writeShim(shimPath string) error {
shimContent := []byte("#!/bin/bash\n$(v which --raw) $@") shimContent := []byte("#!/bin/bash\n$(v python which --raw) $@")
if err := os.WriteFile(shimPath, shimContent, DEFAULT_PERMISSION); err != nil { if err := os.WriteFile(shimPath, shimContent, DEFAULT_PERMISSION); err != nil {
return err return err
} }

29
commands_test.go Normal file
View file

@ -0,0 +1,29 @@
package main
import (
"io/ioutil"
"os"
"strings"
"testing"
state "v/state"
testutils "v/testutils"
)
func TestWriteShim(t *testing.T) {
defer testutils.SetupAndCleanupEnvironment(t)()
os.Mkdir(state.GetStatePath("shims"), 0775)
testShimPath := state.GetStatePath("shims", "testshim")
e := writeShim(testShimPath)
shimContent, _ := ioutil.ReadFile(testShimPath)
if e != nil {
t.Errorf("Errored while writing shim")
}
if !strings.Contains(string(shimContent), "$(v python which --raw) $@") {
t.Errorf("Expected shim to contain pass-through via 'which', got %s", shimContent)
}
}