mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-02-05 11:45:21 +00:00
- Add govulncheck, Snyk, and Trivy vulnerability scanning - Create security workflow for automated scanning on push/PR/schedule - Add gitleaks for secrets detection and prevention - Implement EditorConfig linting with eclint and editorconfig-checker - Update Makefile with security and formatting targets - Create SECURITY.md with vulnerability reporting guidelines - Configure Dependabot for automated dependency updates - Fix all EditorConfig violations across codebase - Update Go version to 1.23.10 to address stdlib vulnerabilities - Add tests for internal/helpers package (80% coverage) - Remove deprecated functions and migrate to error-returning patterns - Fix YAML indentation in test fixtures to resolve test failures
134 lines
3.5 KiB
Go
134 lines
3.5 KiB
Go
package helpers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ivuorinen/gh-action-readme/internal"
|
|
"github.com/ivuorinen/gh-action-readme/testutil"
|
|
)
|
|
|
|
func TestCreateAnalyzer(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
setupConfig func() *internal.AppConfig
|
|
expectAnalyzer bool
|
|
expectWarning bool
|
|
}{
|
|
{
|
|
name: "successful analyzer creation with valid config",
|
|
setupConfig: func() *internal.AppConfig {
|
|
return &internal.AppConfig{
|
|
Theme: "default",
|
|
OutputFormat: "md",
|
|
OutputDir: ".",
|
|
Verbose: false,
|
|
Quiet: false,
|
|
GitHubToken: "fake_token", // Provide token for analyzer creation
|
|
}
|
|
},
|
|
expectAnalyzer: true,
|
|
expectWarning: false,
|
|
},
|
|
{
|
|
name: "analyzer creation without GitHub token",
|
|
setupConfig: func() *internal.AppConfig {
|
|
return &internal.AppConfig{
|
|
Theme: "default",
|
|
OutputFormat: "md",
|
|
OutputDir: ".",
|
|
Verbose: false,
|
|
Quiet: false,
|
|
GitHubToken: "", // No token provided
|
|
}
|
|
},
|
|
expectAnalyzer: true, // Changed: analyzer might still be created but with limited functionality
|
|
expectWarning: false, // Changed: may not warn if token is optional
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
config := tt.setupConfig()
|
|
generator := internal.NewGenerator(config)
|
|
|
|
// Create output instance for testing
|
|
output := &internal.ColoredOutput{
|
|
NoColor: true,
|
|
Quiet: false,
|
|
}
|
|
|
|
analyzer := CreateAnalyzer(generator, output)
|
|
|
|
if tt.expectAnalyzer && analyzer == nil {
|
|
t.Error("expected analyzer to be created, got nil")
|
|
}
|
|
|
|
if !tt.expectAnalyzer && analyzer != nil {
|
|
t.Error("expected analyzer to be nil, got non-nil")
|
|
}
|
|
|
|
// Note: Testing warning output would require more sophisticated mocking
|
|
// of the ColoredOutput, which is beyond the scope of this basic test
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCreateAnalyzerOrExit(t *testing.T) {
|
|
// Only test success case since failure case calls os.Exit
|
|
t.Run("successful analyzer creation", func(t *testing.T) {
|
|
config := &internal.AppConfig{
|
|
Theme: "default",
|
|
OutputFormat: "md",
|
|
OutputDir: ".",
|
|
Verbose: false,
|
|
Quiet: false,
|
|
GitHubToken: "fake_token",
|
|
}
|
|
|
|
generator := internal.NewGenerator(config)
|
|
output := &internal.ColoredOutput{
|
|
NoColor: true,
|
|
Quiet: false,
|
|
}
|
|
|
|
analyzer := CreateAnalyzerOrExit(generator, output)
|
|
|
|
if analyzer == nil {
|
|
t.Error("expected analyzer to be created, got nil")
|
|
}
|
|
})
|
|
|
|
// Note: We cannot test the failure case because it calls os.Exit(1)
|
|
// In a real-world scenario, we might refactor to return errors instead
|
|
}
|
|
|
|
func TestCreateAnalyzer_Integration(t *testing.T) {
|
|
// Test integration with actual generator functionality
|
|
tmpDir, cleanup := testutil.TempDir(t)
|
|
defer cleanup()
|
|
|
|
config := &internal.AppConfig{
|
|
Theme: "default",
|
|
OutputFormat: "md",
|
|
OutputDir: tmpDir,
|
|
Verbose: false,
|
|
Quiet: true, // Keep quiet to avoid output noise
|
|
GitHubToken: "fake_token",
|
|
}
|
|
|
|
generator := internal.NewGenerator(config)
|
|
output := internal.NewColoredOutput(true) // quiet mode
|
|
|
|
analyzer := CreateAnalyzer(generator, output)
|
|
|
|
// Verify analyzer has expected properties
|
|
if analyzer != nil {
|
|
// Basic verification that analyzer was created successfully
|
|
// More detailed testing would require examining internal state
|
|
t.Log("Analyzer created successfully")
|
|
} else {
|
|
// This might be expected if GitHub token validation fails
|
|
t.Log("Analyzer creation failed - this may be expected without valid GitHub token")
|
|
}
|
|
}
|