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

Function TestSetupShellStartupFiles

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

Source from the content-addressed store, hash-verified

340}
341
342func TestSetupShellStartupFiles(t *testing.T) {
343 tmpDir := t.TempDir()
344
345 // Create a mock zsh shell
346 shell := &DevboxShell{
347 name: shZsh,
348 userShellrcPath: filepath.Join(tmpDir, ".zshrc"),
349 }
350
351 // Create some test zsh startup files
352 startupFiles := []string{".zshenv", ".zprofile", ".zlogin", ".zlogout", ".zimrc"}
353 for _, filename := range startupFiles {
354 filePath := filepath.Join(tmpDir, filename)
355 err := os.WriteFile(filePath, []byte("# Test content for "+filename), 0o644)
356 if err != nil {
357 t.Fatalf("Failed to create test file %s: %v", filename, err)
358 }
359 }
360
361 // Create a temporary directory for shell settings
362 shellSettingsDir := t.TempDir()
363
364 // Call setupShellStartupFiles
365 shell.setupShellStartupFiles(shellSettingsDir)
366
367 // Check that all startup files were created in the shell settings directory
368 for _, filename := range startupFiles {
369 expectedPath := filepath.Join(shellSettingsDir, filename)
370 _, err := os.Stat(expectedPath)
371 if err != nil {
372 t.Errorf("Expected startup file %s to be created, but got error: %v", filename, err)
373 }
374
375 // Check that the file contains the expected template content
376 content, err := os.ReadFile(expectedPath)
377 if err != nil {
378 t.Errorf("Failed to read created file %s: %v", filename, err)
379 continue
380 }
381
382 contentStr := string(content)
383 expectedOldPath := filepath.Join(tmpDir, filename)
384 if !strings.Contains(contentStr, expectedOldPath) {
385 t.Errorf("Expected file %s to contain path %s, but content was: %s", filename, expectedOldPath, contentStr)
386 }
387
388 if !strings.Contains(contentStr, "DEVBOX_ZDOTDIR") {
389 t.Errorf("Expected file %s to contain ZDOTDIR handling, but content was: %s", filename, contentStr)
390 }
391 }
392}
393
394func TestWriteDevboxShellrcBash(t *testing.T) {
395 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected