style: Extract UI constants and refactor main view rendering (#30)

- [x] Add golangci-lint configuration with gocritic ifElseChain disabled
- [x] Rename error variables to avoid shadowing (createErr, watcherErr, watchErr, etc.)
- [x] Replace `interface{}` with `any` type alias throughout codebase
- [x] Add package-level documentation comments to all internal packages
- [x] Reorder struct fields alphabetically for consistency
- [x] Extract UI constants (terminal dimensions, column widths, colors) to constants.go
- [x] Refactor BubbleTeaUI main view rendering into smaller helper functions
- [x] Simplify nested conditionals and improve code clarity
- [x] Add `isForwardDisabled()` helper method to BubbleTeaUI
- [x] Update file permissions from 0644 to 0600 in config tests
- [x] Add `#nosec` comments and error suppression where appropriate
- [x] Improve test table struct field ordering for readability
- [x] Fix resource parsing in AddForward using strings.SplitN
- [x] Add comprehensive tests for new UI helper functions and constants
This commit is contained in:
2026-01-13 09:37:45 +00:00
committed by GitHub
parent 3d71f64901
commit 96ae1d45e0
54 changed files with 1319 additions and 730 deletions
+33 -53
View File
@@ -10,36 +10,28 @@ import (
// MockDiscovery is a mock implementation of DiscoveryInterface for testing
type MockDiscovery struct {
mu sync.Mutex
// Return values
Contexts []string
CurrentContext string
Namespaces []string
Pods []k8s.PodInfo
PodsWithSelector []k8s.PodInfo
Services []k8s.ServiceInfo
// Errors to return
ListContextsErr error
GetCurrentContextErr error
ListNamespacesErr error
ListPodsErr error
ListPodsWithSelectorErr error
ListServicesErr error
// Call tracking
ListPodsErr error
ListServicesErr error
ListPodsWithSelectorErr error
ListContextsErr error
GetCurrentContextErr error
ListNamespacesErr error
LastSelector string
CurrentContext string
LastNamespace string
LastContextName string
PodsWithSelector []k8s.PodInfo
Services []k8s.ServiceInfo
Pods []k8s.PodInfo
Namespaces []string
Contexts []string
ListContextsCalls int
GetCurrentContextCalls int
ListNamespacesCalls int
ListPodsCalls int
ListPodsWithSelectorCalls int
ListServicesCalls int
// Captured arguments
LastContextName string
LastNamespace string
LastSelector string
mu sync.Mutex
}
func NewMockDiscovery() *MockDiscovery {
@@ -104,34 +96,26 @@ func (m *MockDiscovery) ListServices(ctx context.Context, contextName, namespace
// MockMutator is a mock implementation of MutatorInterface for testing
type MockMutator struct {
mu sync.Mutex
// Errors to return
AddForwardErr error
RemoveForwardsErr error
RemoveForwardByIDErr error
UpdateForwardErr error
// Call tracking
AddForwardCalls int
RemoveForwardsCalls int
RemoveForwardByIDCalls int
UpdateForwardCalls int
// Captured arguments
LastContextName string
LastNamespaceName string
LastForward config.Forward
LastOldID string
LastRemovedID string
LastPredicate func(ctx, ns string, fwd config.Forward) bool
// Storage for testing
Forwards []struct {
AddForwardErr error
RemoveForwardsErr error
LastPredicate func(ctx, ns string, fwd config.Forward) bool
LastContextName string
LastOldID string
LastNamespaceName string
LastRemovedID string
Forwards []struct {
Context string
Namespace string
Forward config.Forward
}
LastForward config.Forward
RemoveForwardByIDCalls int
UpdateForwardCalls int
RemoveForwardsCalls int
AddForwardCalls int
mu sync.Mutex
}
func NewMockMutator() *MockMutator {
@@ -186,14 +170,10 @@ func (m *MockMutator) UpdateForward(oldID, newContextName, newNamespaceName stri
// MockHTTPLogSubscriber is a mock for HTTP log subscription
type MockHTTPLogSubscriber struct {
mu sync.Mutex
// Subscription tracking
Subscriptions map[string]func(HTTPLogEntry)
CleanupCalls int
// Control
ShouldFail bool
mu sync.Mutex
ShouldFail bool
}
func NewMockHTTPLogSubscriber() *MockHTTPLogSubscriber {
@@ -237,11 +217,11 @@ func (m *MockHTTPLogSubscriber) GetSubscriberFunc() HTTPLogSubscriber {
// MockToggleCallback tracks toggle callback invocations
type MockToggleCallback struct {
mu sync.Mutex
Calls []struct {
ID string
Enable bool
}
mu sync.Mutex
}
func NewMockToggleCallback() *MockToggleCallback {