Files
upaas/internal/service/deploy/deploy_images_test.go
T
sneak 8c61b5ae77 Remove images from earlier deploys after a successful deploy (closes #216)
After a successful deploy, upaas now removes the app's images other than
the one the running container uses and the previous one, which rollback
starts. Removing an image also removes the untagged images it was built on
unless another image still needs them. Images left by other stages of a
multi-stage build are not tied to the app and stay.

Model: opus-5-5
2026-09-23 10:05:02 +00:00

49 lines
1.0 KiB
Go

package deploy_test
import (
"database/sql"
"testing"
"github.com/stretchr/testify/assert"
"sneak.berlin/go/upaas/internal/docker"
"sneak.berlin/go/upaas/internal/models"
"sneak.berlin/go/upaas/internal/service/deploy"
)
const currentImage = "sha256:current"
func TestUnusedImages_KeepsCurrentAndRollbackImage(t *testing.T) {
t.Parallel()
app := &models.App{
ImageID: sql.NullString{String: currentImage, Valid: true},
PreviousImageID: sql.NullString{String: "sha256:previous", Valid: true},
}
images := []docker.ImageID{
"sha256:oldest",
"sha256:previous",
"sha256:older",
currentImage,
}
assert.Equal(t,
[]docker.ImageID{"sha256:oldest", "sha256:older"},
deploy.UnusedImages(images, app),
)
}
func TestUnusedImages_FirstDeployHasNoRollbackImage(t *testing.T) {
t.Parallel()
app := &models.App{
ImageID: sql.NullString{String: currentImage, Valid: true},
}
images := []docker.ImageID{currentImage, "sha256:failed"}
assert.Equal(t,
[]docker.ImageID{"sha256:failed"},
deploy.UnusedImages(images, app),
)
}