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 | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "fmt" | |
| 5 | - | "os" | |
| 6 | 5 | "path/filepath" | |
| 7 | 6 | "testing" | |
| 8 | - | "time" | |
| 9 | 7 | ||
| 10 | 8 | "github.com/bnema/archup/internal/config" | |
| 11 | 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 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 substring | 453 | + | // 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) { | |||
| 271 | 271 | ||
| 272 | 272 | // TestReposPhaseStructure tests that ReposPhase can be properly initialized | |
| 273 | 273 | func TestReposPhaseStructure(t *testing.T) { | |
| 274 | + | ctrl := gomock.NewController(t) | |
| 275 | + | defer ctrl.Finish() | |
| 276 | + | ||
| 274 | 277 | // Create a temporary directory for log file | |
| 275 | 278 | tmpDir := t.TempDir() | |
| 276 | 279 | logPath := filepath.Join(tmpDir, "test.log") | |
| @@ -285,8 +288,13 @@ func TestReposPhaseStructure(t *testing.T) { | |||
| 285 | 288 | // Create config | |
| 286 | 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 | 296 | // Create ReposPhase | |
| 289 | - | phase := NewReposPhase(cfg, log) | |
| 297 | + | phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec) | |
| 290 | 298 | ||
| 291 | 299 | // Verify initialization | |
| 292 | 300 | if phase == nil { | |
| @@ -516,12 +524,20 @@ func TestReposPhasePreCheckValidation(t *testing.T) { | |||
| 516 | 524 | ||
| 517 | 525 | for _, tt := range tests { | |
| 518 | 526 | t.Run(tt.name, func(t *testing.T) { | |
| 527 | + | ctrl := gomock.NewController(t) | |
| 528 | + | defer ctrl.Finish() | |
| 529 | + | ||
| 519 | 530 | // Create config with test AUR helper | |
| 520 | 531 | cfg := config.NewConfig("test") | |
| 521 | 532 | 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 | 539 | // Create ReposPhase | |
| 524 | - | phase := NewReposPhase(cfg, log) | |
| 540 | + | phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec) | |
| 525 | 541 | ||
| 526 | 542 | // Note: PreCheck also validates /mnt is mounted and pacman.conf exists | |
| 527 | 543 | // 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 initialized | 272 | // 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 file | 277 | // 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 config | 288 | // 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 ReposPhase | 296 | // Create ReposPhase | ||
| 289 | - | phase := NewReposPhase(cfg, log) | 297 | + | phase := NewReposPhase(cfg, log, mockFS, mockSysExec, mockChrExec) |
| 290 | 298 | ||||
| 291 | // Verify initialization | 299 | // 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 helper | 530 | // Create config with test AUR helper | ||
| 520 | cfg := config.NewConfig("test") | 531 | cfg := config.NewConfig("test") | ||
| 521 | cfg.AURHelper = tt.aurHelper | 532 | 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 ReposPhase | 539 | // 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 exists | 542 | // Note: PreCheck also validates /mnt is mounted and pacman.conf exists | ||
| 527 | // In a real test environment, these would fail, so we're only testing | 543 | // 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 | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "fmt" | |
| 5 | - | "os" | |
| 6 | 5 | "path/filepath" | |
| 7 | 6 | "testing" | |
| 8 | - | "time" | |
| 9 | 7 | ||
| 10 | 8 | "github.com/bnema/archup/internal/config" | |
| 11 | 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 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 substring | 306 | + | // 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 } | |||