Files
Charon/backend/internal/api/routes/routes_import_test.go
GitHub Actions d7939bed70 feat: add ManualDNSChallenge component and related hooks for manual DNS challenge management
- Implemented `useManualChallenge`, `useChallengePoll`, and `useManualChallengeMutations` hooks for managing manual DNS challenges.
- Created tests for the `useManualChallenge` hooks to ensure correct fetching and mutation behavior.
- Added `ManualDNSChallenge` component for displaying challenge details and actions.
- Developed end-to-end tests for the Manual DNS Provider feature, covering provider selection, challenge UI, and accessibility compliance.
- Included error handling tests for verification failures and network errors.
2026-01-12 04:01:40 +00:00

56 lines
1.5 KiB
Go

package routes_test
import (
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"github.com/Wikid82/charon/backend/internal/api/routes"
"github.com/Wikid82/charon/backend/internal/models"
)
func setupTestImportDB(t *testing.T) *gorm.DB {
dsn := "file:" + t.Name() + "?mode=memory&cache=shared"
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
if err != nil {
t.Fatalf("failed to connect to test database: %v", err)
}
_ = db.AutoMigrate(&models.ImportSession{}, &models.ProxyHost{})
return db
}
func TestRegisterImportHandler(t *testing.T) {
gin.SetMode(gin.TestMode)
db := setupTestImportDB(t)
router := gin.New()
routes.RegisterImportHandler(router, db, "echo", "/tmp", "/import/Caddyfile")
// Verify routes are registered by checking the routes list
routeInfo := router.Routes()
expectedRoutes := map[string]bool{
"GET /api/v1/import/status": false,
"GET /api/v1/import/preview": false,
"POST /api/v1/import/upload": false,
"POST /api/v1/import/upload-multi": false,
"POST /api/v1/import/detect-imports": false,
"POST /api/v1/import/commit": false,
"DELETE /api/v1/import/cancel": false,
}
for _, route := range routeInfo {
key := route.Method + " " + route.Path
if _, exists := expectedRoutes[key]; exists {
expectedRoutes[key] = true
}
}
for route, found := range expectedRoutes {
assert.True(t, found, "route %s should be registered", route)
}
}