Skip to content

Commit dd43354

Browse files
test(installer): add coverage for custom install shell/dotfiles/macos steps
- Verify runCustomInstall runs the three setup steps end-to-end - Verify RemoteConfig.DotfilesRepo is propagated to cfg.DotfilesURL - Verify soft errors are collected and returned (not swallowed) - Verify stepDotfiles uses cfg.DotfilesURL when env var is unset - Verify OPENBOOT_DOTFILES env var takes priority over cfg.DotfilesURL - Guard all tests against ambient OPENBOOT_DOTFILES env var Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 7820d6d commit dd43354

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

internal/installer/installer_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package installer
22

33
import (
44
"encoding/json"
5+
"io"
56
"os"
67
"path/filepath"
78
"testing"
@@ -413,3 +414,108 @@ func TestRunFromSnapshot_SoftFailuresReturnError(t *testing.T) {
413414
err := RunFromSnapshot(cfg)
414415
assert.NoError(t, err)
415416
}
417+
418+
func TestRunCustomInstall_RunsShellDotfilesMacOS(t *testing.T) {
419+
tmpDir := t.TempDir()
420+
t.Setenv("HOME", tmpDir)
421+
t.Setenv("OPENBOOT_DOTFILES", "")
422+
423+
cfg := &config.Config{
424+
DryRun: true,
425+
Shell: "skip",
426+
Macos: "skip",
427+
RemoteConfig: &config.RemoteConfig{
428+
Username: "testuser",
429+
Slug: "default",
430+
Packages: []string{"git"},
431+
},
432+
}
433+
434+
err := runCustomInstall(cfg)
435+
assert.NoError(t, err)
436+
}
437+
438+
func TestRunCustomInstall_DotfilesRepoPopulatesDotfilesURL(t *testing.T) {
439+
tmpDir := t.TempDir()
440+
t.Setenv("HOME", tmpDir)
441+
442+
cfg := &config.Config{
443+
DryRun: true,
444+
Shell: "skip",
445+
Macos: "skip",
446+
Dotfiles: "skip",
447+
RemoteConfig: &config.RemoteConfig{
448+
Username: "testuser",
449+
Slug: "default",
450+
Packages: []string{"git"},
451+
DotfilesRepo: "https://github.com/testuser/dotfiles",
452+
},
453+
}
454+
455+
err := runCustomInstall(cfg)
456+
assert.NoError(t, err)
457+
assert.Equal(t, "https://github.com/testuser/dotfiles", cfg.DotfilesURL)
458+
}
459+
460+
func TestRunCustomInstall_SoftErrorsAreReturned(t *testing.T) {
461+
tmpDir := t.TempDir()
462+
t.Setenv("HOME", tmpDir)
463+
464+
cfg := &config.Config{
465+
DryRun: true,
466+
Shell: "skip",
467+
Macos: "skip",
468+
RemoteConfig: &config.RemoteConfig{
469+
Username: "testuser",
470+
Slug: "default",
471+
Packages: []string{"git"},
472+
},
473+
Dotfiles: "link",
474+
}
475+
476+
err := runCustomInstall(cfg)
477+
assert.Error(t, err)
478+
assert.Contains(t, err.Error(), "dotfiles")
479+
}
480+
481+
func TestStepDotfiles_UsesDotfilesURLFromConfig(t *testing.T) {
482+
tmpDir := t.TempDir()
483+
t.Setenv("HOME", tmpDir)
484+
t.Setenv("OPENBOOT_DOTFILES", "")
485+
486+
cfg := &config.Config{
487+
DryRun: true,
488+
Dotfiles: "clone",
489+
DotfilesURL: "https://github.com/testuser/dotfiles",
490+
}
491+
492+
err := stepDotfiles(cfg)
493+
assert.NoError(t, err)
494+
}
495+
496+
func TestStepDotfiles_EnvVarTakesPriorityOverConfigURL(t *testing.T) {
497+
tmpDir := t.TempDir()
498+
t.Setenv("HOME", tmpDir)
499+
t.Setenv("OPENBOOT_DOTFILES", "https://github.com/from-env/dotfiles")
500+
501+
r, w, _ := os.Pipe()
502+
origStdout := os.Stdout
503+
os.Stdout = w
504+
505+
cfg := &config.Config{
506+
DryRun: true,
507+
Dotfiles: "clone",
508+
DotfilesURL: "https://github.com/from-config/dotfiles",
509+
}
510+
511+
err := stepDotfiles(cfg)
512+
513+
w.Close()
514+
os.Stdout = origStdout
515+
out, _ := io.ReadAll(r)
516+
output := string(out)
517+
518+
assert.NoError(t, err)
519+
assert.Contains(t, output, "from-env")
520+
assert.NotContains(t, output, "from-config")
521+
}

0 commit comments

Comments
 (0)