mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-03-19 21:02:56 +00:00
fix(tests): remove unused test constants and helpers
Delete dead test code that caused 41 staticcheck U1000 violations: - cli/test_constants.go (25 unused constants) - cli/terminal_test_helpers.go (unused type, method, 7 variables) - fileproc/test_constants.go (5 unused constants) - fileproc/processor_test.go (2 unused helper functions)
This commit is contained in:
@@ -1,68 +0,0 @@
|
|||||||
package cli
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
// terminalEnvSetup defines environment variables for terminal detection tests.
|
|
||||||
type terminalEnvSetup struct {
|
|
||||||
Term string
|
|
||||||
CI string
|
|
||||||
GitHubActions string
|
|
||||||
NoColor string
|
|
||||||
ForceColor string
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply sets up the environment variables using t.Setenv.
|
|
||||||
func (e terminalEnvSetup) apply(t *testing.T) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
// Always set all environment variables to ensure isolation
|
|
||||||
// Empty string explicitly unsets the variable in the test environment
|
|
||||||
t.Setenv("TERM", e.Term)
|
|
||||||
t.Setenv("CI", e.CI)
|
|
||||||
t.Setenv("GITHUB_ACTIONS", e.GitHubActions)
|
|
||||||
t.Setenv("NO_COLOR", e.NoColor)
|
|
||||||
t.Setenv("FORCE_COLOR", e.ForceColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common terminal environment setups for reuse across tests.
|
|
||||||
var (
|
|
||||||
envDefaultTerminal = terminalEnvSetup{
|
|
||||||
Term: "xterm-256color",
|
|
||||||
CI: "",
|
|
||||||
NoColor: "",
|
|
||||||
ForceColor: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
envDumbTerminal = terminalEnvSetup{
|
|
||||||
Term: "dumb",
|
|
||||||
}
|
|
||||||
|
|
||||||
envCIWithoutGitHub = terminalEnvSetup{
|
|
||||||
Term: "xterm",
|
|
||||||
CI: "true",
|
|
||||||
GitHubActions: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
envGitHubActions = terminalEnvSetup{
|
|
||||||
Term: "xterm",
|
|
||||||
CI: "true",
|
|
||||||
GitHubActions: "true",
|
|
||||||
NoColor: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
envNoColor = terminalEnvSetup{
|
|
||||||
Term: "xterm-256color",
|
|
||||||
CI: "",
|
|
||||||
NoColor: "1",
|
|
||||||
ForceColor: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
envForceColor = terminalEnvSetup{
|
|
||||||
Term: "dumb",
|
|
||||||
ForceColor: "1",
|
|
||||||
}
|
|
||||||
|
|
||||||
envEmptyTerm = terminalEnvSetup{
|
|
||||||
Term: "",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package cli
|
|
||||||
|
|
||||||
// Test constants to avoid duplication in test files.
|
|
||||||
// These constants are used across multiple test files in the cli package.
|
|
||||||
const (
|
|
||||||
// Error messages
|
|
||||||
testErrFileNotFound = "file not found"
|
|
||||||
testErrPermissionDenied = "permission denied"
|
|
||||||
testErrInvalidFormat = "invalid format"
|
|
||||||
testErrOther = "other error"
|
|
||||||
testErrEncoding = "encoding error"
|
|
||||||
testErrSourceRequired = "source directory is required"
|
|
||||||
testErrPathTraversal = "path traversal attempt detected"
|
|
||||||
testPathTraversalPath = "../../../etc/passwd"
|
|
||||||
|
|
||||||
// Suggestion messages
|
|
||||||
testSuggestionsHeader = "Suggestions:"
|
|
||||||
testSuggestCheckPerms = "Check file/directory permissions"
|
|
||||||
testSuggestVerifyPath = "Verify the path is correct"
|
|
||||||
testSuggestFormat = "Use a supported format: markdown, json, yaml"
|
|
||||||
testSuggestFormatEx = "Example: -format markdown"
|
|
||||||
testSuggestCheckArgs = "Check your command line arguments"
|
|
||||||
testSuggestHelp = "Run with --help for usage information"
|
|
||||||
testSuggestDiskSpace = "Verify available disk space"
|
|
||||||
testSuggestReduceConcur = "Try with -concurrency 1 to reduce resource usage"
|
|
||||||
|
|
||||||
// UI test strings
|
|
||||||
testWithColors = "with colors"
|
|
||||||
testWithoutColors = "without colors"
|
|
||||||
testProcessingMsg = "Processing files"
|
|
||||||
|
|
||||||
// Flag names
|
|
||||||
testFlagSource = "-source"
|
|
||||||
testFlagConcurrency = "-concurrency"
|
|
||||||
|
|
||||||
// Test file paths
|
|
||||||
testFilePath1 = "/test/file1.go"
|
|
||||||
testFilePath2 = "/test/file2.go"
|
|
||||||
|
|
||||||
// Output markers
|
|
||||||
testErrorSuffix = " Error"
|
|
||||||
)
|
|
||||||
@@ -31,54 +31,6 @@ func writeTempConfig(t *testing.T, content string) string {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
// collectWriteRequests runs a processing function and collects all WriteRequests.
|
|
||||||
// This helper wraps the common pattern of channel + goroutine + WaitGroup.
|
|
||||||
func collectWriteRequests(t *testing.T, process func(ch chan fileproc.WriteRequest)) []fileproc.WriteRequest {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
ch := make(chan fileproc.WriteRequest, 10)
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Go(func() {
|
|
||||||
defer close(ch)
|
|
||||||
process(ch)
|
|
||||||
})
|
|
||||||
|
|
||||||
results := make([]fileproc.WriteRequest, 0)
|
|
||||||
for req := range ch {
|
|
||||||
results = append(results, req)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
// collectWriteRequestsWithContext runs a processing function with context and collects all WriteRequests.
|
|
||||||
func collectWriteRequestsWithContext(
|
|
||||||
ctx context.Context,
|
|
||||||
t *testing.T,
|
|
||||||
process func(ctx context.Context, ch chan fileproc.WriteRequest) error,
|
|
||||||
) ([]fileproc.WriteRequest, error) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
ch := make(chan fileproc.WriteRequest, 10)
|
|
||||||
var processErr error
|
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Go(func() {
|
|
||||||
defer close(ch)
|
|
||||||
processErr = process(ctx, ch)
|
|
||||||
})
|
|
||||||
|
|
||||||
results := make([]fileproc.WriteRequest, 0)
|
|
||||||
for req := range ch {
|
|
||||||
results = append(results, req)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
return results, processErr
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestProcessFile(t *testing.T) {
|
func TestProcessFile(t *testing.T) {
|
||||||
// Reset and load default config to ensure proper file size limits
|
// Reset and load default config to ensure proper file size limits
|
||||||
testutil.ResetViperConfig(t, "")
|
testutil.ResetViperConfig(t, "")
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
package fileproc
|
|
||||||
|
|
||||||
// Test constants to avoid duplication in test files.
|
|
||||||
// These constants are used across multiple test files in the fileproc package.
|
|
||||||
const (
|
|
||||||
// Backpressure configuration keys
|
|
||||||
testBackpressureEnabled = "backpressure.enabled"
|
|
||||||
testBackpressureMaxMemory = "backpressure.maxMemoryUsage"
|
|
||||||
testBackpressureMemoryCheck = "backpressure.memoryCheckInterval"
|
|
||||||
testBackpressureMaxFiles = "backpressure.maxPendingFiles"
|
|
||||||
testBackpressureMaxWrites = "backpressure.maxPendingWrites"
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user