MCPcopy Index your code
hub / github.com/jetify-com/devbox / TestWriteDevboxShellrcWithZDOTDIR

Function TestWriteDevboxShellrcWithZDOTDIR

internal/devbox/shell_test.go:442–490  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

440}
441
442func TestWriteDevboxShellrcWithZDOTDIR(t *testing.T) {
443 tmpDir := t.TempDir()
444
445 // Set up ZDOTDIR environment
446 t.Setenv("ZDOTDIR", tmpDir)
447
448 // Create a test zsh rc file in the custom ZDOTDIR
449 customZshrcPath := filepath.Join(tmpDir, ".zshrc")
450 zshrcContent := "# Custom zsh configuration\nexport CUSTOM_VAR=value"
451 err := os.WriteFile(customZshrcPath, []byte(zshrcContent), 0o644)
452 if err != nil {
453 t.Fatalf("Failed to create test .zshrc: %v", err)
454 }
455
456 // Create a mock devbox
457 devbox := &Devbox{projectDir: "/test/project"}
458
459 // Create a zsh shell - this should pick up the ZDOTDIR
460 shell := initShellBinaryFields("/usr/bin/zsh")
461 shell.devbox = devbox
462 shell.projectDir = "/test/project"
463
464 if shell.userShellrcPath != customZshrcPath {
465 t.Error("Expected shellrc path to respect ZDOTDIR")
466 }
467
468 // Write the devbox shellrc
469 shellrcPath, err := shell.writeDevboxShellrc()
470 if err != nil {
471 t.Fatalf("Failed to write devbox shellrc: %v", err)
472 }
473
474 // Read and verify the content
475 content, err := os.ReadFile(shellrcPath)
476 if err != nil {
477 t.Fatalf("Failed to read generated shellrc: %v", err)
478 }
479
480 contentStr := string(content)
481 // Check that it contains zsh-specific ZDOTDIR handling
482 if !strings.Contains(contentStr, "DEVBOX_ZDOTDIR") {
483 t.Error("Expected shellrc to contain ZDOTDIR handling for zsh")
484 }
485
486 // Check that it sources the custom .zshrc
487 if !strings.Contains(contentStr, customZshrcPath) {
488 t.Error("Expected shellrc to source the custom .zshrc file")
489 }
490}
491
492// TestWriteDevboxShellrcZDOTDIRWithSpaces guards against a regression where the
493// `[ -f <path> ]` guard around sourcing the user's shellrc was unquoted. When

Callers

nothing calls this directly

Calls 3

initShellBinaryFieldsFunction · 0.85
writeDevboxShellrcMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected