New tool to help with github management. Read all about it in the [README](https://github.com/fleetdm/fleet/blob/gkarr-gm/tools/github-manage/README.md) on this branch.
4.3 KiB
Test Suite Summary for github-manage/pkg/ghapi
Overview
I have created comprehensive tests for all files and functions in the github-manage/pkg/ghapi folder. The test suite provides 40.5% code coverage and includes both unit tests and performance benchmarks.
Test Files Created
1. cli_test.go
Functions tested:
RunCommandAndReturnOutput()- Command execution and output capture- Error handling for invalid commands
- Empty command handling
- Windows/Linux compatibility testing
2. issues_test.go
Functions tested:
ParseJSONtoIssues()- JSON parsing for GitHub issues- Issue structure validation and JSON marshaling
- Error handling for malformed JSON
- Empty and null input handling
Functions skipped (require GitHub CLI):
GetIssues()AddLabelToIssue()RemoveLabelFromIssue()SetMilestoneToIssue()
3. models_test.go
Functions tested:
ConvertItemsToIssues()- Project items to issues conversion- Comprehensive struct marshaling/unmarshaling for all data models:
AuthorLabelMilestoneIssueProjectItemProjectItemsResponseProjectFieldsResponse
4. projects_test.go
Functions tested:
ParseJSONtoProjectItems()- Project items JSON parsingAliasesglobal variable validationLoadProjectFields()- Caching mechanism testingLookupProjectFieldName()- Field lookup functionalityFindFieldValueByName()- Field value search with fuzzy matchingSetProjectItemFieldValue()- Stub function testing
Functions skipped (require GitHub CLI):
GetProjectItems()GetProjectFields()
5. views_test.go
Functions tested:
ViewTypeconstants validationMDM_LABELconstant validationNewView()- View creation with various configurations- View struct JSON marshaling
- Empty filters handling
Functions skipped (require GitHub CLI):
GetMDMTicketsEstimated()
6. workflows_test.go
Functions tested:
BulkSprintKickoff()- Stub function testingBulkMilestoneClose()- Stub function testing- Function signature validation
- Empty slice handling
Functions skipped (require GitHub CLI):
BulkAddLabel()(with non-empty slices)BulkRemoveLabel()(with non-empty slices)
7. suite_test.go
Features:
- Comprehensive test suite runner
- Performance benchmarks for critical functions:
- JSON parsing performance
- Data conversion performance
- Organized test execution
Test Results
PASS
ok fleetdm/gm/pkg/ghapi 0.468s
coverage: 40.5% of statements
Benchmark Results:
ParseJSONtoIssues: ~5,176 ns/opParseJSONtoProjectItems: ~6,235 ns/opConvertItemsToIssues: ~264 ns/op
Test Categories
✅ Fully Tested
- JSON parsing and validation
- Data structure conversions
- Struct marshaling/unmarshaling
- Caching mechanisms
- Constant validation
- Error handling
- Edge cases (empty/null inputs)
⚠️ Partially Tested
- CLI-dependent functions (structure tested, execution skipped)
- Network-dependent operations
- GitHub API interactions
🔧 Testing Limitations
Some functions are skipped because they require:
- GitHub CLI (
gh) installation and authentication - Network connectivity
- Access to Fleet's GitHub repository
- Live GitHub API responses
Running the Tests
# Run all tests
go test ./pkg/ghapi -v
# Run with coverage
go test ./pkg/ghapi -cover
# Run benchmarks
go test ./pkg/ghapi -bench=.
# Run specific test categories
go test ./pkg/ghapi -run TestCLI -v
go test ./pkg/ghapi -run TestModels -v
go test ./pkg/ghapi -run TestSuite -v
Recommendations for Enhanced Testing
-
Add Dependency Injection: Modify functions to accept interfaces for external dependencies (GitHub CLI, HTTP clients)
-
Implement Mocking: Create mock implementations for:
RunCommandAndReturnOutput()- GitHub CLI responses
- Network calls
-
Integration Tests: Set up a test environment with:
- Test GitHub repository
- Mock GitHub API server
- Authenticated GitHub CLI
-
Property-Based Testing: Use property-based testing libraries for JSON parsing and data conversions
The test suite provides a solid foundation for ensuring code quality and catching regressions while maintaining fast execution times by skipping external dependencies.