Skip to content

Commit 7ec6060

Browse files
committed
test(e2e): move all e2e tests into Tart VMs
All non-VM e2e tests were running on the developer's local machine, reading local brew state and running openboot doctor/snapshot/diff/clean against the host system. - Change build tag from `e2e` → `e2e && vm` on all 5 files - Replace exec.Command(binary) with vmRunDevBinary(t, vm, bin, args) - Each test now boots a Tart VM, installs Homebrew, copies the binary - Remove tests already covered by vm_commands_test.go (version, help, doctor, unknown command/flag, snapshot, logout duplicates) - `go build -tags="e2e"` now matches no packages (nothing runs locally) - `go build -tags="e2e,vm"` compiles cleanly
1 parent 5cf770a commit 7ec6060

File tree

5 files changed

+288
-409
lines changed

5 files changed

+288
-409
lines changed

test/e2e/clean_e2e_test.go

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,98 @@
1-
//go:build e2e
1+
//go:build e2e && vm
22

33
package e2e
44

55
import (
6-
"os"
7-
"os/exec"
86
"strings"
97
"testing"
108

119
"github.com/openbootdotdev/openboot/testutil"
1210
"github.com/stretchr/testify/assert"
11+
"github.com/stretchr/testify/require"
1312
)
1413

1514
func TestE2E_Clean_DryRun_FromFile(t *testing.T) {
16-
binary := testutil.BuildTestBinary(t)
17-
tmpDir := t.TempDir()
15+
if testing.Short() {
16+
t.Skip("skipping VM test in short mode")
17+
}
18+
19+
vm := testutil.NewTartVM(t)
20+
vmInstallHomebrew(t, vm)
21+
bin := vmCopyDevBinary(t, vm)
1822

1923
// Create a snapshot with a small set of packages — system will have "extra"
20-
snapshotPath := writeTestSnapshot(t, tmpDir, []string{"git"}, []string{}, []string{})
24+
snapshotPath := "/tmp/clean-test-snapshot.json"
25+
vmWriteTestSnapshot(t, vm, snapshotPath, []string{"git"}, []string{}, []string{})
2126

2227
// Capture installed packages before
23-
beforePkgs, err := testutil.GetInstalledBrewPackages()
24-
if err != nil {
25-
t.Skipf("cannot list brew packages: %v", err)
26-
}
27-
28-
cmd := exec.Command(binary, "clean", "--from", snapshotPath, "--dry-run")
29-
output, err := cmd.CombinedOutput()
30-
outStr := string(output)
28+
beforePkgs := vmBrewList(t, vm)
3129

32-
assert.NoError(t, err, "clean --dry-run should succeed, output: %s", outStr)
30+
output, err := vmRunDevBinary(t, vm, bin, "clean --from "+snapshotPath+" --dry-run")
31+
assert.NoError(t, err, "clean --dry-run should succeed, output: %s", output)
3332
assert.True(t,
34-
strings.Contains(outStr, "DRY-RUN") || strings.Contains(outStr, "dry run") || strings.Contains(outStr, "Dry run"),
35-
"output should mention dry-run mode, got: %s", outStr)
33+
strings.Contains(output, "DRY-RUN") || strings.Contains(output, "dry run") || strings.Contains(output, "Dry run"),
34+
"output should mention dry-run mode, got: %s", output)
3635

3736
// Verify nothing was actually removed
38-
afterPkgs, err := testutil.GetInstalledBrewPackages()
39-
if err != nil {
40-
t.Skipf("cannot list brew packages: %v", err)
41-
}
37+
afterPkgs := vmBrewList(t, vm)
4238
assert.Equal(t, len(beforePkgs), len(afterPkgs),
4339
"dry-run should not remove any packages (before=%d, after=%d)", len(beforePkgs), len(afterPkgs))
4440
}
4541

4642
func TestE2E_Clean_MissingFile(t *testing.T) {
47-
binary := testutil.BuildTestBinary(t)
43+
if testing.Short() {
44+
t.Skip("skipping VM test in short mode")
45+
}
4846

49-
cmd := exec.Command(binary, "clean", "--from", "/tmp/nonexistent-snapshot-99999.json")
50-
output, err := cmd.CombinedOutput()
51-
outStr := string(output)
47+
vm := testutil.NewTartVM(t)
48+
vmInstallHomebrew(t, vm)
49+
bin := vmCopyDevBinary(t, vm)
5250

51+
output, err := vmRunDevBinary(t, vm, bin, "clean --from /tmp/nonexistent-snapshot-99999.json")
5352
assert.Error(t, err, "clean with missing file should fail")
5453
assert.True(t,
55-
strings.Contains(outStr, "not found") || strings.Contains(outStr, "no such file") || strings.Contains(outStr, "snapshot"),
56-
"error should mention file issue, got: %s", outStr)
54+
strings.Contains(output, "not found") || strings.Contains(output, "no such file") || strings.Contains(output, "snapshot"),
55+
"error should mention file issue, got: %s", output)
5756
}
5857

5958
func TestE2E_Clean_NoLocalSnapshot(t *testing.T) {
60-
binary := testutil.BuildTestBinary(t)
59+
if testing.Short() {
60+
t.Skip("skipping VM test in short mode")
61+
}
6162

62-
// Run clean without flags — tries local snapshot
63-
cmd := exec.Command(binary, "clean")
64-
// Set HOME to a temp dir so no local snapshot exists
65-
tmpHome := t.TempDir()
66-
cmd.Env = append(os.Environ(), "HOME="+tmpHome)
63+
vm := testutil.NewTartVM(t)
64+
vmInstallHomebrew(t, vm)
65+
bin := vmCopyDevBinary(t, vm)
6766

68-
output, err := cmd.CombinedOutput()
69-
outStr := string(output)
67+
// Run clean without flags — tries local snapshot which won't exist in fresh VM
68+
// Use a temp HOME dir in the VM with no snapshot
69+
_, err := vm.Run("mkdir -p /tmp/clean-no-snapshot-home")
70+
require.NoError(t, err)
7071

72+
output, err := vm.RunWithEnv(
73+
map[string]string{"PATH": brewPath, "HOME": "/tmp/clean-no-snapshot-home"},
74+
bin+" clean",
75+
)
7176
if err != nil {
7277
assert.True(t,
73-
strings.Contains(outStr, "snapshot") || strings.Contains(outStr, "--from") || strings.Contains(outStr, "--user"),
74-
"error should guide user, got: %s", outStr)
78+
strings.Contains(output, "snapshot") || strings.Contains(output, "--from") || strings.Contains(output, "--user"),
79+
"error should guide user, got: %s", output)
7580
}
7681
}
7782

7883
func TestE2E_Clean_HelpFlag(t *testing.T) {
79-
binary := testutil.BuildTestBinary(t)
84+
if testing.Short() {
85+
t.Skip("skipping VM test in short mode")
86+
}
8087

81-
cmd := exec.Command(binary, "clean", "--help")
82-
output, err := cmd.CombinedOutput()
83-
outStr := string(output)
88+
vm := testutil.NewTartVM(t)
89+
vmInstallHomebrew(t, vm)
90+
bin := vmCopyDevBinary(t, vm)
8491

92+
output, err := vmRunDevBinary(t, vm, bin, "clean --help")
8593
assert.NoError(t, err, "clean --help should succeed")
86-
assert.Contains(t, outStr, "clean")
87-
assert.Contains(t, outStr, "--from")
88-
assert.Contains(t, outStr, "--user")
89-
assert.Contains(t, outStr, "--dry-run")
94+
assert.Contains(t, output, "clean")
95+
assert.Contains(t, output, "--from")
96+
assert.Contains(t, output, "--user")
97+
assert.Contains(t, output, "--dry-run")
9098
}

0 commit comments

Comments
 (0)