All checks were successful
Check / check (pull_request) Successful in 11m24s
Wire the imageID parameter (returned from docker build) through createAndStartContainer and buildContainerOptions instead of reconstructing a mutable tag via fmt.Sprintf. This ensures containers reference the immutable image digest, avoiding tag-reuse races when deploys overlap. Changes: - Rename _ string to imageID string in createAndStartContainer - Change buildContainerOptions to accept imageID string instead of deploymentID int64 - Use imageID directly as the Image field in container options - Update rollback path to pass previousImageID directly - Add test verifying imageID flows through to container options - Add database.NewTestDatabase and logger.NewForTest test helpers
42 lines
723 B
Go
42 lines
723 B
Go
package database
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/upaas/internal/config"
|
|
"git.eeqj.de/sneak/upaas/internal/logger"
|
|
)
|
|
|
|
// NewTestDatabase creates an in-memory Database for testing.
|
|
// It runs migrations so all tables are available.
|
|
func NewTestDatabase(t *testing.T) *Database {
|
|
t.Helper()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
cfg := &config.Config{
|
|
DataDir: tmpDir,
|
|
}
|
|
|
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
|
logWrapper := logger.NewForTest(log)
|
|
|
|
db, err := New(nil, Params{
|
|
Logger: logWrapper,
|
|
Config: cfg,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("failed to create test database: %v", err)
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
if db.database != nil {
|
|
_ = db.database.Close()
|
|
}
|
|
})
|
|
|
|
return db
|
|
}
|