mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-03-01 02:55:17 +00:00
refactor: major codebase improvements and test framework overhaul
This commit represents a comprehensive refactoring of the codebase focused on improving code quality, testability, and maintainability. Key improvements: - Implement dependency injection and interface-based architecture - Add comprehensive test framework with fixtures and test suites - Fix all linting issues (errcheck, gosec, staticcheck, goconst, etc.) - Achieve full EditorConfig compliance across all files - Replace hardcoded test data with proper fixture files - Add configuration loader with hierarchical config support - Improve error handling with contextual information - Add progress indicators for better user feedback - Enhance Makefile with help system and improved editorconfig commands - Consolidate constants and remove deprecated code - Strengthen validation logic for GitHub Actions - Add focused consumer interfaces for better separation of concerns Testing improvements: - Add comprehensive integration tests - Implement test executor pattern for better test organization - Create extensive YAML fixture library for testing - Fix all failing tests and improve test coverage - Add validation test fixtures to avoid embedded YAML in Go files Build and tooling: - Update Makefile to show help by default - Fix editorconfig commands to use eclint properly - Add comprehensive help documentation to all make targets - Improve file selection patterns to avoid glob errors This refactoring maintains backward compatibility while significantly improving the internal architecture and developer experience.
This commit is contained in:
142
internal/progress_test.go
Normal file
142
internal/progress_test.go
Normal file
@@ -0,0 +1,142 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
func TestProgressBarManager_CreateProgressBar(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
quiet bool
|
||||
description string
|
||||
total int
|
||||
expectNil bool
|
||||
}{
|
||||
{
|
||||
name: "normal progress bar",
|
||||
quiet: false,
|
||||
description: "Test progress",
|
||||
total: 10,
|
||||
expectNil: false,
|
||||
},
|
||||
{
|
||||
name: "quiet mode returns nil",
|
||||
quiet: true,
|
||||
description: "Test progress",
|
||||
total: 10,
|
||||
expectNil: true,
|
||||
},
|
||||
{
|
||||
name: "single item returns nil",
|
||||
quiet: false,
|
||||
description: "Test progress",
|
||||
total: 1,
|
||||
expectNil: true,
|
||||
},
|
||||
{
|
||||
name: "zero items returns nil",
|
||||
quiet: false,
|
||||
description: "Test progress",
|
||||
total: 0,
|
||||
expectNil: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
pm := NewProgressBarManager(tt.quiet)
|
||||
bar := pm.CreateProgressBar(tt.description, tt.total)
|
||||
|
||||
if tt.expectNil {
|
||||
if bar != nil {
|
||||
t.Errorf("expected nil progress bar, got %v", bar)
|
||||
}
|
||||
} else {
|
||||
if bar == nil {
|
||||
t.Error("expected progress bar, got nil")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressBarManager_CreateProgressBarForFiles(t *testing.T) {
|
||||
pm := NewProgressBarManager(false)
|
||||
files := []string{"file1.yml", "file2.yml", "file3.yml"}
|
||||
|
||||
bar := pm.CreateProgressBarForFiles("Processing files", files)
|
||||
|
||||
if bar == nil {
|
||||
t.Error("expected progress bar for multiple files, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressBarManager_FinishProgressBar(_ *testing.T) {
|
||||
pm := NewProgressBarManager(false)
|
||||
|
||||
// Test with nil bar (should not panic)
|
||||
pm.FinishProgressBar(nil)
|
||||
|
||||
// Test with actual bar
|
||||
bar := pm.CreateProgressBar("Test", 5)
|
||||
if bar != nil {
|
||||
pm.FinishProgressBar(bar)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressBarManager_UpdateProgressBar(_ *testing.T) {
|
||||
pm := NewProgressBarManager(false)
|
||||
|
||||
// Test with nil bar (should not panic)
|
||||
pm.UpdateProgressBar(nil)
|
||||
|
||||
// Test with actual bar
|
||||
bar := pm.CreateProgressBar("Test", 5)
|
||||
if bar != nil {
|
||||
pm.UpdateProgressBar(bar)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressBarManager_ProcessWithProgressBar(t *testing.T) {
|
||||
pm := NewProgressBarManager(false)
|
||||
items := []string{"item1", "item2", "item3"}
|
||||
|
||||
processedItems := make([]string, 0)
|
||||
processFunc := func(item string, _ *progressbar.ProgressBar) {
|
||||
processedItems = append(processedItems, item)
|
||||
}
|
||||
|
||||
pm.ProcessWithProgressBar("Processing items", items, processFunc)
|
||||
|
||||
if len(processedItems) != len(items) {
|
||||
t.Errorf("expected %d processed items, got %d", len(items), len(processedItems))
|
||||
}
|
||||
|
||||
for i, item := range items {
|
||||
if processedItems[i] != item {
|
||||
t.Errorf("expected item %s at position %d, got %s", item, i, processedItems[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProgressBarManager_ProcessWithProgressBar_QuietMode(t *testing.T) {
|
||||
pm := NewProgressBarManager(true) // quiet mode
|
||||
items := []string{"item1", "item2"}
|
||||
|
||||
processedItems := make([]string, 0)
|
||||
processFunc := func(item string, bar *progressbar.ProgressBar) {
|
||||
processedItems = append(processedItems, item)
|
||||
// In quiet mode, bar should be nil
|
||||
if bar != nil {
|
||||
t.Error("expected nil progress bar in quiet mode")
|
||||
}
|
||||
}
|
||||
|
||||
pm.ProcessWithProgressBar("Processing items", items, processFunc)
|
||||
|
||||
if len(processedItems) != len(items) {
|
||||
t.Errorf("expected %d processed items, got %d", len(items), len(processedItems))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user