Files
aptly/api/storage_test.go
T
Nick Bozhenko 40ba104838 Add comprehensive CI/CD improvements and test coverage
This commit introduces major enhancements to the CI/CD pipeline and testing infrastructure:

CI/CD Improvements:
- Consolidated modern and legacy CI workflows into a single comprehensive pipeline
- Removed all publishing functionality from CI (no longer needed)
- Added 8 new advanced testing jobs for pull requests:
  * advanced-coverage: Detailed coverage analysis with base branch comparison
  * performance-profile: CPU and memory profiling with benchmarks
  * fuzz-test: Automated fuzz testing for supported packages
  * deep-analysis: Multiple static analysis tools (shadow, ineffassign, gosec, staticcheck)
  * mutation-test: Tests effectiveness of test suite on changed files
  * dependency-audit: Security vulnerabilities and outdated dependency checks
  * stress-test: Race detection with 100 iterations and parallel testing
  * test-report-summary: Aggregates all reports into a single PR comment
- Enabled RUN_LONG_TESTS by default for thorough testing
- Added automatic PR comment generation with all test results

Testing Infrastructure:
- Added comprehensive test files across all packages to improve coverage
- Implemented unit tests for previously untested packages
- Added race condition tests for concurrent operations
- Created integration tests for API endpoints
- Added storage backend tests (etcd, goleveldb)
- Implemented command-line interface tests

Local Testing Support:
- Added act configuration for testing GitHub Actions locally
- Created docker-compose.ci.yml for full CI environment simulation
- Updated CONTRIBUTING.md with detailed local testing instructions

Documentation Updates:
- Added comprehensive CI documentation to CONTRIBUTING.md
- Removed obsolete references to Travis CI
- Updated Go version requirements to 1.24
- Added act usage instructions and examples

Other Improvements:
- Updated .gitignore to exclude coverage reports and build artifacts
- Added test-act.yml workflow for testing act functionality
- Created CI_SUMMARY.md documenting all CI capabilities

These changes transform aptly's CI from a basic testing pipeline into a comprehensive quality assurance system that provides immediate feedback on code quality, performance, security, and test effectiveness.
2025-07-10 12:00:54 -04:00

76 lines
2.0 KiB
Go

package api
import (
"net/http"
"net/http/httptest"
"github.com/gin-gonic/gin"
. "gopkg.in/check.v1"
)
type StorageTestSuite struct {
router *gin.Engine
}
var _ = Suite(&StorageTestSuite{})
func (s *StorageTestSuite) SetUpTest(c *C) {
s.router = gin.New()
s.router.GET("/api/storage", apiDiskFree)
gin.SetMode(gin.TestMode)
}
func (s *StorageTestSuite) TestStorageListStructure(c *C) {
// Test storage list endpoint structure
req, _ := http.NewRequest("GET", "/api/storage", nil)
w := httptest.NewRecorder()
s.router.ServeHTTP(w, req)
c.Check(w.Code, Equals, 200)
c.Check(w.Header().Get("Content-Type"), Equals, "application/json; charset=utf-8")
// Should return some storage information without error
}
func (s *StorageTestSuite) TestStorageHTTPMethods(c *C) {
// Test that only GET method is allowed
deniedMethods := []string{"POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"}
for _, method := range deniedMethods {
req, _ := http.NewRequest(method, "/api/storage", nil)
w := httptest.NewRecorder()
s.router.ServeHTTP(w, req)
c.Check(w.Code, Equals, 404, Commentf("Method: %s should be denied", method))
}
}
func (s *StorageTestSuite) TestStorageEndpointReliability(c *C) {
// Test multiple calls to ensure endpoint is reliable
for i := 0; i < 5; i++ {
req, _ := http.NewRequest("GET", "/api/storage", nil)
w := httptest.NewRecorder()
s.router.ServeHTTP(w, req)
c.Check(w.Code, Equals, 200, Commentf("Call #%d", i+1))
c.Check(w.Header().Get("Content-Type"), Equals, "application/json; charset=utf-8")
}
}
func (s *StorageTestSuite) TestStorageResponseStructure(c *C) {
// Test that response structure is consistent
req, _ := http.NewRequest("GET", "/api/storage", nil)
w := httptest.NewRecorder()
s.router.ServeHTTP(w, req)
c.Check(w.Code, Equals, 200)
// Should have valid JSON response
body := w.Body.String()
c.Check(len(body), Not(Equals), 0)
// Should start with valid JSON structure
c.Check(body[0], Equals, byte('{'), Commentf("Response should be JSON object"))
}