MCPcopy Create free account
hub / github.com/jetify-com/devbox / TestResolveEditorBinary

Function TestResolveEditorBinary

internal/boxcli/integrate_test.go:12–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestResolveEditorBinary(t *testing.T) {
13 // Create a temp directory with a bin/code binary to simulate
14 // a VS Code installation (e.g., WSL's VSCODE_CWD).
15 installDir := t.TempDir()
16 binDir := filepath.Join(installDir, "bin")
17 if err := os.MkdirAll(binDir, 0o755); err != nil {
18 t.Fatal(err)
19 }
20 codePath := filepath.Join(binDir, "code")
21 if err := os.WriteFile(codePath, []byte("#!/bin/sh\n"), 0o755); err != nil {
22 t.Fatal(err)
23 }
24
25 // A directory that does NOT contain bin/code, simulating
26 // macOS where VSCODE_CWD is the workspace directory.
27 workspaceDir := t.TempDir()
28
29 tests := []struct {
30 name string
31 vscodeCWD string // empty means unset
32 ideName string
33 want string
34 }{
35 {
36 name: "VSCODE_CWD unset falls back to bare name",
37 ideName: "code",
38 want: "code",
39 },
40 {
41 name: "VSCODE_CWD with valid binary uses full path",
42 vscodeCWD: installDir,
43 ideName: "code",
44 want: filepath.Join(installDir, "bin", "code"),
45 },
46 {
47 name: "VSCODE_CWD without binary falls back to bare name",
48 vscodeCWD: workspaceDir,
49 ideName: "code",
50 want: "code",
51 },
52 {
53 name: "non-default IDE name resolves correctly",
54 vscodeCWD: workspaceDir,
55 ideName: "cursor",
56 want: "cursor",
57 },
58 }
59
60 for _, testCase := range tests {
61 t.Run(testCase.name, func(t *testing.T) {
62 if testCase.vscodeCWD != "" {
63 t.Setenv("VSCODE_CWD", testCase.vscodeCWD)
64 } else {
65 os.Unsetenv("VSCODE_CWD")
66 }
67
68 got := resolveEditorBinary(testCase.ideName)
69 if got != testCase.want {

Callers

nothing calls this directly

Calls 2

resolveEditorBinaryFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected