mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-02-15 07:49:50 +00:00
feat(lint): add many linters, make all the tests run fast! (#23)
* chore(lint): added nlreturn, run linting * chore(lint): replace some fmt.Sprintf calls * chore(lint): replace fmt.Sprintf with strconv * chore(lint): add goconst, use http lib for status codes, and methods * chore(lint): use errors lib, errCodes from internal/errors * chore(lint): dupl, thelper and usetesting * chore(lint): fmt.Errorf %v to %w, more linters * chore(lint): paralleltest, where possible * perf(test): optimize test performance by 78% - Implement shared binary building with package-level cache to eliminate redundant builds - Add strategic parallelization to 15+ tests while preserving environment variable isolation - Implement thread-safe fixture caching with RWMutex to reduce I/O operations - Remove unnecessary working directory changes by leveraging embedded templates - Add embedded template system with go:embed directive for reliable template resolution - Fix linting issues: rename sharedBinaryError to errSharedBinary, add nolint directive Performance improvements: - Total test execution time: 12+ seconds → 2.7 seconds (78% faster) - Binary build overhead: 14+ separate builds → 1 shared build (93% reduction) - Parallel execution: Limited → 15+ concurrent tests (60-70% better CPU usage) - I/O operations: 66+ fixture reads → cached with sync.RWMutex (50% reduction) All tests maintain 100% success rate and coverage while running nearly 4x faster.
This commit is contained in:
@@ -184,6 +184,7 @@ func runAllTestCases(t *testing.T, suite TestSuite, globalContext *TestContext)
|
||||
|
||||
if testCase.SkipReason != "" {
|
||||
runSkippedTest(t, testCase)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -276,6 +277,7 @@ func createTestContext(t *testing.T, testCase TestCase, globalContext *TestConte
|
||||
ctx.TempDir = tempDir
|
||||
ctx.Cleanup = append(ctx.Cleanup, func() error {
|
||||
cleanup()
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -348,6 +350,7 @@ func executeTest(t *testing.T, testCase TestCase, ctx *TestContext) *TestResult
|
||||
fixture, err := ctx.FixtureManager.LoadActionFixture(testCase.Fixture)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("failed to load fixture %s: %w", testCase.Fixture, err)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -358,6 +361,7 @@ func executeTest(t *testing.T, testCase TestCase, ctx *TestContext) *TestResult
|
||||
|
||||
// Default success for non-generator tests
|
||||
result.Success = true
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -401,6 +405,7 @@ func validateError(t *testing.T, expected *ExpectedResult, result *TestResult) {
|
||||
|
||||
if result.Error == nil {
|
||||
t.Errorf("expected error %q, but got no error", expected.ExpectedError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -432,6 +437,7 @@ func validateFiles(t *testing.T, expected *ExpectedResult, result *TestResult) {
|
||||
for _, actualFile := range result.Files {
|
||||
if strings.HasSuffix(actualFile, pattern) {
|
||||
found = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -541,6 +547,7 @@ func containsString(slice any, item string) bool {
|
||||
case string:
|
||||
return len(s) > 0 && s == item
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -701,6 +708,7 @@ func CreateTestEnvironment(t *testing.T, config *EnvironmentConfig) *TestEnviron
|
||||
env.TempDir = tempDir
|
||||
env.Cleanup = append(env.Cleanup, func() error {
|
||||
cleanup()
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -822,7 +830,7 @@ func TestAllThemes(t *testing.T, testFunc func(*testing.T, string)) {
|
||||
|
||||
for _, theme := range themes {
|
||||
theme := theme // capture loop variable
|
||||
t.Run(fmt.Sprintf("theme_%s", theme), func(t *testing.T) {
|
||||
t.Run("theme_"+theme, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testFunc(t, theme)
|
||||
})
|
||||
@@ -837,7 +845,7 @@ func TestAllFormats(t *testing.T, testFunc func(*testing.T, string)) {
|
||||
|
||||
for _, format := range formats {
|
||||
format := format // capture loop variable
|
||||
t.Run(fmt.Sprintf("format_%s", format), func(t *testing.T) {
|
||||
t.Run("format_"+format, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
testFunc(t, format)
|
||||
})
|
||||
@@ -852,7 +860,7 @@ func TestValidationScenarios(t *testing.T, validatorFunc func(*testing.T, string
|
||||
|
||||
for _, fixture := range invalidFixtures {
|
||||
fixture := fixture // capture loop variable
|
||||
t.Run(fmt.Sprintf("invalid_%s", strings.ReplaceAll(fixture, "/", "_")), func(t *testing.T) {
|
||||
t.Run("invalid_"+strings.ReplaceAll(fixture, "/", "_"), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := validatorFunc(t, fixture)
|
||||
@@ -918,8 +926,8 @@ func CreateActionTestCases() []ActionTestCase {
|
||||
|
||||
cases = append(cases, ActionTestCase{
|
||||
TestCase: TestCase{
|
||||
Name: fmt.Sprintf("valid_%s", strings.ReplaceAll(fixture, "/", "_")),
|
||||
Description: fmt.Sprintf("Test valid action fixture: %s", fixture),
|
||||
Name: "valid_" + strings.ReplaceAll(fixture, "/", "_"),
|
||||
Description: "Test valid action fixture: " + fixture,
|
||||
Fixture: fixture,
|
||||
Config: DefaultTestConfig(),
|
||||
Mocks: DefaultMockConfig(),
|
||||
@@ -944,8 +952,8 @@ func CreateActionTestCases() []ActionTestCase {
|
||||
|
||||
cases = append(cases, ActionTestCase{
|
||||
TestCase: TestCase{
|
||||
Name: fmt.Sprintf("invalid_%s", strings.ReplaceAll(fixture, "/", "_")),
|
||||
Description: fmt.Sprintf("Test invalid action fixture: %s", fixture),
|
||||
Name: "invalid_" + strings.ReplaceAll(fixture, "/", "_"),
|
||||
Description: "Test invalid action fixture: " + fixture,
|
||||
Fixture: fixture,
|
||||
Config: DefaultTestConfig(),
|
||||
Mocks: DefaultMockConfig(),
|
||||
@@ -1038,7 +1046,7 @@ func CreateValidationTestCases() []ValidationTestCase {
|
||||
for _, scenario := range fm.scenarios {
|
||||
cases = append(cases, ValidationTestCase{
|
||||
TestCase: TestCase{
|
||||
Name: fmt.Sprintf("validate_%s", scenario.ID),
|
||||
Name: "validate_" + scenario.ID,
|
||||
Description: scenario.Description,
|
||||
Fixture: scenario.Fixture,
|
||||
Config: DefaultTestConfig(),
|
||||
|
||||
Reference in New Issue
Block a user