mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-09 10:57:55 +00:00
ff66310b73
Test Coverage Improvements: - Increased API test coverage from 43.2% to 46.3% - Added comprehensive tests for database operations, metrics, and middleware - Enhanced existing test suites with additional edge cases and error scenarios - Removed redundant cmd/*_test.go files (already covered by system tests) API Enhancements: - Added metadata update capability to PUT /api/publish endpoint - Now supports updating Origin, Label, Suite, Codename, NotAutomatic, and ButAutomaticUpgrades fields - Metadata changes are applied during the publish operation Infrastructure Updates: - Fixed etcd batch write panic with proper retry logic - Enhanced S3 upload with better concurrent operation handling - Improved task management with better error handling and race condition prevention - Updated etcd install script to support both x86_64 and arm64 architectures Code Quality: - Fixed go vet issues and code formatting problems - Enhanced error messages and logging throughout the codebase - Improved resource cleanup in test suites - Better handling of nil values and edge cases Build System: - Updated Makefile with improved dependency management - Enhanced .golangci.yml configuration for better linting - Added VERSION file management - Updated .gitignore for better coverage tracking Documentation: - Integrated macOS testing guide into CONTRIBUTING.md - Added platform-specific setup instructions - Improved test running documentation with multiple options
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
|
|
"github.com/aptly-dev/aptly/deb"
|
|
"github.com/gin-gonic/gin"
|
|
. "gopkg.in/check.v1"
|
|
)
|
|
|
|
type ApiPackagesSuite struct {
|
|
APISuite
|
|
}
|
|
|
|
var _ = Suite(&ApiPackagesSuite{})
|
|
|
|
func (s *ApiPackagesSuite) TestShowPackages(c *C) {
|
|
// Test showPackages function with nil reflist
|
|
w := httptest.NewRecorder()
|
|
ginCtx, _ := gin.CreateTestContext(w)
|
|
ginCtx.Request = httptest.NewRequest("GET", "/api/test", nil)
|
|
|
|
showPackages(ginCtx, nil, s.context.NewCollectionFactory())
|
|
|
|
// Should return 404 for nil reflist
|
|
c.Check(w.Code, Equals, 404)
|
|
}
|
|
|
|
func (s *ApiPackagesSuite) TestShowPackagesWithEmptyList(c *C) {
|
|
// Test showPackages with empty package reflist
|
|
w := httptest.NewRecorder()
|
|
ginCtx, _ := gin.CreateTestContext(w)
|
|
ginCtx.Request = httptest.NewRequest("GET", "/api/test", nil)
|
|
|
|
reflist := deb.NewPackageRefList()
|
|
showPackages(ginCtx, reflist, s.context.NewCollectionFactory())
|
|
|
|
c.Check(w.Code, Equals, 200)
|
|
|
|
var result []string
|
|
err := json.Unmarshal(w.Body.Bytes(), &result)
|
|
c.Check(err, IsNil)
|
|
c.Check(len(result), Equals, 0)
|
|
}
|
|
|
|
func (s *ApiPackagesSuite) TestShowPackagesCompact(c *C) {
|
|
// Test showPackages with compact format (default)
|
|
w := httptest.NewRecorder()
|
|
ginCtx, _ := gin.CreateTestContext(w)
|
|
ginCtx.Request = httptest.NewRequest("GET", "/api/test", nil)
|
|
|
|
reflist := deb.NewPackageRefList()
|
|
showPackages(ginCtx, reflist, s.context.NewCollectionFactory())
|
|
|
|
c.Check(w.Code, Equals, 200)
|
|
}
|
|
|
|
func (s *ApiPackagesSuite) TestShowPackagesDetails(c *C) {
|
|
// Test showPackages with details format
|
|
w := httptest.NewRecorder()
|
|
ginCtx, _ := gin.CreateTestContext(w)
|
|
ginCtx.Request = httptest.NewRequest("GET", "/api/test?format=details", nil)
|
|
|
|
reflist := deb.NewPackageRefList()
|
|
showPackages(ginCtx, reflist, s.context.NewCollectionFactory())
|
|
|
|
c.Check(w.Code, Equals, 200)
|
|
|
|
var result []*deb.Package
|
|
err := json.Unmarshal(w.Body.Bytes(), &result)
|
|
c.Check(err, IsNil)
|
|
c.Check(len(result), Equals, 0)
|
|
} |