upaas/internal/service/deploy/export_test.go
clawbot 25cd02e1d7 fix: use strings.HasPrefix and delegate export to real cleanup method
- Replace manual string prefix check with strings.HasPrefix (idiomatic Go)
- Refactor CleanupCancelledDeploy export to call the real cleanupCancelledDeploy
  method instead of re-implementing the logic, so tests catch regressions
- Add nil-db guard in Deployment.Save and App.Save to prevent panics when
  models are used without a database connection (e.g. in test exports)
- Fix wsl_v5 lint issue (missing blank line before assignment)
2026-02-19 20:17:06 -08:00

68 lines
1.8 KiB
Go

package deploy
import (
"context"
"log/slog"
"git.eeqj.de/sneak/upaas/internal/config"
"git.eeqj.de/sneak/upaas/internal/docker"
"git.eeqj.de/sneak/upaas/internal/models"
)
// NewTestService creates a Service with minimal dependencies for testing.
func NewTestService(log *slog.Logger) *Service {
return &Service{
log: log,
}
}
// CancelActiveDeploy exposes cancelActiveDeploy for testing.
func (svc *Service) CancelActiveDeploy(appID string) {
svc.cancelActiveDeploy(appID)
}
// RegisterActiveDeploy registers an active deploy for testing.
func (svc *Service) RegisterActiveDeploy(appID string, cancel context.CancelFunc, done chan struct{}) {
svc.activeDeploys.Store(appID, &activeDeploy{cancel: cancel, done: done})
}
// TryLockApp exposes tryLockApp for testing.
func (svc *Service) TryLockApp(appID string) bool {
return svc.tryLockApp(appID)
}
// UnlockApp exposes unlockApp for testing.
func (svc *Service) UnlockApp(appID string) {
svc.unlockApp(appID)
}
// NewTestServiceWithConfig creates a Service with config and docker client for testing.
func NewTestServiceWithConfig(log *slog.Logger, cfg *config.Config, dockerClient *docker.Client) *Service {
return &Service{
log: log,
config: cfg,
docker: dockerClient,
}
}
// CleanupCancelledDeploy exposes cleanupCancelledDeploy for testing.
func (svc *Service) CleanupCancelledDeploy(
ctx context.Context,
appName string,
deploymentID int64,
imageID string,
) {
app := models.NewApp(nil)
app.Name = appName
deployment := models.NewDeployment(nil)
deployment.ID = deploymentID
svc.cleanupCancelledDeploy(ctx, app, deployment, imageID)
}
// GetBuildDirExported exposes GetBuildDir for testing.
func (svc *Service) GetBuildDirExported(appName string) string {
return svc.GetBuildDir(appName)
}