detached 5245050

fix(tests): update test calls and remove unused imports

commit
52450502618f7f5df5dc85481716a11963f57edd
author
bnema · · 2025-10-27 19:14 UTC
committer
bnema · · 2025-10-27 18:12 UTC
parent
1549b62
signature
unsigned
3 files · +20 -44
M internal/phases/preflight_test.go +1 -21
@@ -2,10 +2,8 @@ package phases
22
33 import (
44 "fmt"
5- "os"
65 "path/filepath"
76 "testing"
8- "time"
97
108 "github.com/bnema/archup/internal/config"
119 "github.com/bnema/archup/internal/interfaces/mocks"
@@ -452,22 +450,4 @@ func TestPreflightPhaseCanSkip(t *testing.T) {
452450 }
453451 }
454452
455-// Helper function to check if a string contains a substring
456-func containsSubstring(s, substr string) bool {
457- for i := 0; i < len(s)-len(substr)+1; i++ {
458- if s[i:i+len(substr)] == substr {
459- return true
460- }
461- }
462- return false
463-}
464-
465-// mockFileInfo implements os.FileInfo for testing
466-type mockFileInfo struct{}
467-
468-func (m mockFileInfo) Name() string { return "mock" }
469-func (m mockFileInfo) Size() int64 { return 0 }
470-func (m mockFileInfo) Mode() os.FileMode { return 0 }
471-func (m mockFileInfo) ModTime() time.Time { return time.Now() }
472-func (m mockFileInfo) IsDir() bool { return false }
473-func (m mockFileInfo) Sys() interface{} { return nil }
453+// Helper functions are defined in helpers_test.go to avoid duplication
@@ -2,10 +2,8 @@ package phases
2 2
3 import (3 import (
4 "fmt"4 "fmt"
5- "os"
6 "path/filepath"5 "path/filepath"
7 "testing"6 "testing"
8- "time"
9 7
10 "github.com/bnema/archup/internal/config"8 "github.com/bnema/archup/internal/config"
11 "github.com/bnema/archup/internal/interfaces/mocks"9 "github.com/bnema/archup/internal/interfaces/mocks"
@@ -452,22 +450,4 @@ func TestPreflightPhaseCanSkip(t *testing.T) {
452 }450 }
453 }451 }
454 452
455-// Helper function to check if a string contains a substring453+// Helper functions are defined in helpers_test.go to avoid duplication
456-func containsSubstring(s, substr string) bool {
457- for i := 0; i < len(s)-len(substr)+1; i++ {
458- if s[i:i+len(substr)] == substr {
459- return true
460- }
461- }
462- return false
463-}
464-
465-// mockFileInfo implements os.FileInfo for testing
466-type mockFileInfo struct{}
467-
468-func (m mockFileInfo) Name() string { return "mock" }
469-func (m mockFileInfo) Size() int64 { return 0 }
470-func (m mockFileInfo) Mode() os.FileMode { return 0 }
471-func (m mockFileInfo) ModTime() time.Time { return time.Now() }
472-func (m mockFileInfo) IsDir() bool { return false }
473-func (m mockFileInfo) Sys() interface{} { return nil }
M internal/phases/repos_test.go +18 -2
@@ -271,6 +271,9 @@ func BenchmarkMultilibParsing(b *testing.B) {
271271
272272 // TestReposPhaseStructure tests that ReposPhase can be properly initialized
273273 func TestReposPhaseStructure(t *testing.T) {
274+ ctrl := gomock.NewController(t)
275+ defer ctrl.Finish()
276+
274277 // Create a temporary directory for log file
275278 tmpDir := t.TempDir()
276279 logPath := filepath.Join(tmpDir, "test.log")
@@ -285,8 +288,13 @@ func TestReposPhaseStructure(t *testing.T) {
285288 // Create config
286289 cfg := config.NewConfig("test")
287290
291+ // Create mocks
292+ mockFS := mocks.NewMockFileSystem(ctrl)
293+ mockSysExec := mocks.NewMockSystemExecutor(ctrl)
294+ mockChrExec := mocks.NewMockChrootExecutor(ctrl)
295+
288296 // Create ReposPhase
289- phase := NewReposPhase(cfg, log)
297+ phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec)
290298
291299 // Verify initialization
292300 if phase == nil {
@@ -516,12 +524,20 @@ func TestReposPhasePreCheckValidation(t *testing.T) {
516524
517525 for _, tt := range tests {
518526 t.Run(tt.name, func(t *testing.T) {
527+ ctrl := gomock.NewController(t)
528+ defer ctrl.Finish()
529+
519530 // Create config with test AUR helper
520531 cfg := config.NewConfig("test")
521532 cfg.AURHelper = tt.aurHelper
522533
534+ // Create mocks
535+ mockFS := mocks.NewMockFileSystem(ctrl)
536+ mockSysExec := mocks.NewMockSystemExecutor(ctrl)
537+ mockChrExec := mocks.NewMockChrootExecutor(ctrl)
538+
523539 // Create ReposPhase
524- phase := NewReposPhase(cfg, log)
540+ phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec)
525541
526542 // Note: PreCheck also validates /mnt is mounted and pacman.conf exists
527543 // In a real test environment, these would fail, so we're only testing
@@ -271,6 +271,9 @@ func BenchmarkMultilibParsing(b *testing.B) {
271 271
272 // TestReposPhaseStructure tests that ReposPhase can be properly initialized272 // TestReposPhaseStructure tests that ReposPhase can be properly initialized
273 func TestReposPhaseStructure(t *testing.T) {273 func TestReposPhaseStructure(t *testing.T) {
274+ ctrl := gomock.NewController(t)
275+ defer ctrl.Finish()
276+
274 // Create a temporary directory for log file277 // Create a temporary directory for log file
275 tmpDir := t.TempDir()278 tmpDir := t.TempDir()
276 logPath := filepath.Join(tmpDir, "test.log")279 logPath := filepath.Join(tmpDir, "test.log")
@@ -285,8 +288,13 @@ func TestReposPhaseStructure(t *testing.T) {
285 // Create config288 // Create config
286 cfg := config.NewConfig("test")289 cfg := config.NewConfig("test")
287 290
291+ // Create mocks
292+ mockFS := mocks.NewMockFileSystem(ctrl)
293+ mockSysExec := mocks.NewMockSystemExecutor(ctrl)
294+ mockChrExec := mocks.NewMockChrootExecutor(ctrl)
295+
288 // Create ReposPhase296 // Create ReposPhase
289- phase := NewReposPhase(cfg, log)297+ phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec)
290 298
291 // Verify initialization299 // Verify initialization
292 if phase == nil {300 if phase == nil {
@@ -516,12 +524,20 @@ func TestReposPhasePreCheckValidation(t *testing.T) {
516 524
517 for _, tt := range tests {525 for _, tt := range tests {
518 t.Run(tt.name, func(t *testing.T) {526 t.Run(tt.name, func(t *testing.T) {
527+ ctrl := gomock.NewController(t)
528+ defer ctrl.Finish()
529+
519 // Create config with test AUR helper530 // Create config with test AUR helper
520 cfg := config.NewConfig("test")531 cfg := config.NewConfig("test")
521 cfg.AURHelper = tt.aurHelper532 cfg.AURHelper = tt.aurHelper
522 533
534+ // Create mocks
535+ mockFS := mocks.NewMockFileSystem(ctrl)
536+ mockSysExec := mocks.NewMockSystemExecutor(ctrl)
537+ mockChrExec := mocks.NewMockChrootExecutor(ctrl)
538+
523 // Create ReposPhase539 // Create ReposPhase
524- phase := NewReposPhase(cfg, log)540+ phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec)
525 541
526 // Note: PreCheck also validates /mnt is mounted and pacman.conf exists542 // Note: PreCheck also validates /mnt is mounted and pacman.conf exists
527 // In a real test environment, these would fail, so we're only testing543 // In a real test environment, these would fail, so we're only testing
M internal/phases/systemconfig_test.go +1 -21
@@ -2,10 +2,8 @@ package phases
22
33 import (
44 "fmt"
5- "os"
65 "path/filepath"
76 "testing"
8- "time"
97
108 "github.com/bnema/archup/internal/config"
119 "github.com/bnema/archup/internal/interfaces/mocks"
@@ -305,22 +303,4 @@ func TestConfigPhaseCanSkip(t *testing.T) {
305303 }
306304 }
307305
308-// Helper function to check if a string contains a substring
309-func containsSubstring(s, substr string) bool {
310- for i := 0; i < len(s)-len(substr)+1; i++ {
311- if s[i:i+len(substr)] == substr {
312- return true
313- }
314- }
315- return false
316-}
317-
318-// mockFileInfo implements os.FileInfo for testing
319-type mockFileInfo struct{}
320-
321-func (m mockFileInfo) Name() string { return "mock" }
322-func (m mockFileInfo) Size() int64 { return 0 }
323-func (m mockFileInfo) Mode() os.FileMode { return 0 }
324-func (m mockFileInfo) ModTime() time.Time { return time.Now() }
325-func (m mockFileInfo) IsDir() bool { return false }
326-func (m mockFileInfo) Sys() interface{} { return nil }
306+// Helper functions are defined in helpers_test.go to avoid duplication
@@ -2,10 +2,8 @@ package phases
2 2
3 import (3 import (
4 "fmt"4 "fmt"
5- "os"
6 "path/filepath"5 "path/filepath"
7 "testing"6 "testing"
8- "time"
9 7
10 "github.com/bnema/archup/internal/config"8 "github.com/bnema/archup/internal/config"
11 "github.com/bnema/archup/internal/interfaces/mocks"9 "github.com/bnema/archup/internal/interfaces/mocks"
@@ -305,22 +303,4 @@ func TestConfigPhaseCanSkip(t *testing.T) {
305 }303 }
306 }304 }
307 305
308-// Helper function to check if a string contains a substring306+// Helper functions are defined in helpers_test.go to avoid duplication
309-func containsSubstring(s, substr string) bool {
310- for i := 0; i < len(s)-len(substr)+1; i++ {
311- if s[i:i+len(substr)] == substr {
312- return true
313- }
314- }
315- return false
316-}
317-
318-// mockFileInfo implements os.FileInfo for testing
319-type mockFileInfo struct{}
320-
321-func (m mockFileInfo) Name() string { return "mock" }
322-func (m mockFileInfo) Size() int64 { return 0 }
323-func (m mockFileInfo) Mode() os.FileMode { return 0 }
324-func (m mockFileInfo) ModTime() time.Time { return time.Now() }
325-func (m mockFileInfo) IsDir() bool { return false }
326-func (m mockFileInfo) Sys() interface{} { return nil }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 0

    ↑↓ moveenter openesc close