chore: save current changes

This commit is contained in:
2026-02-18 07:02:17 +03:00
parent 2e973b6d78
commit 71f73e2f1d
10 changed files with 822 additions and 374 deletions

View File

@@ -30,15 +30,11 @@ func (m *mockConfigService) GetByUUID(uuid string, ownerUsername string) (*model
func TestExportCSV_Success(t *testing.T) {
gin.SetMode(gin.TestMode)
// Create a basic mock component service that doesn't panic
mockComponentService := &services.ComponentService{}
// Create handler with mocks
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{},
mockComponentService,
nil,
)
@@ -88,7 +84,7 @@ func TestExportCSV_Success(t *testing.T) {
expectedBOM := []byte{0xEF, 0xBB, 0xBF}
actualBOM := responseBody[:3]
if bytes.Compare(actualBOM, expectedBOM) != 0 {
if !bytes.Equal(actualBOM, expectedBOM) {
t.Errorf("UTF-8 BOM mismatch. Expected %v, got %v", expectedBOM, actualBOM)
}
@@ -101,19 +97,18 @@ func TestExportCSV_Success(t *testing.T) {
t.Errorf("Failed to parse CSV header: %v", err)
}
if len(header) != 6 {
t.Errorf("Expected 6 columns, got %d", len(header))
if len(header) != 8 {
t.Errorf("Expected 8 columns, got %d", len(header))
}
}
func TestExportCSV_InvalidRequest(t *testing.T) {
gin.SetMode(gin.TestMode)
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{},
&services.ComponentService{},
nil,
)
@@ -143,11 +138,10 @@ func TestExportCSV_InvalidRequest(t *testing.T) {
func TestExportCSV_EmptyItems(t *testing.T) {
gin.SetMode(gin.TestMode)
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{},
&services.ComponentService{},
nil,
)
@@ -185,11 +179,10 @@ func TestExportConfigCSV_Success(t *testing.T) {
CreatedAt: time.Now(),
}
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{config: mockConfig},
&services.ComponentService{},
nil,
)
@@ -227,7 +220,7 @@ func TestExportConfigCSV_Success(t *testing.T) {
expectedBOM := []byte{0xEF, 0xBB, 0xBF}
actualBOM := responseBody[:3]
if bytes.Compare(actualBOM, expectedBOM) != 0 {
if !bytes.Equal(actualBOM, expectedBOM) {
t.Errorf("UTF-8 BOM mismatch")
}
}
@@ -235,11 +228,10 @@ func TestExportConfigCSV_Success(t *testing.T) {
func TestExportConfigCSV_NotFound(t *testing.T) {
gin.SetMode(gin.TestMode)
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{err: errors.New("config not found")},
&services.ComponentService{},
nil,
)
@@ -280,11 +272,10 @@ func TestExportConfigCSV_EmptyItems(t *testing.T) {
CreatedAt: time.Now(),
}
exportSvc := services.NewExportService(config.ExportConfig{}, nil)
exportSvc := services.NewExportService(config.ExportConfig{}, nil, nil)
handler := NewExportHandler(
exportSvc,
&mockConfigService{config: mockConfig},
&services.ComponentService{},
nil,
)