Check / check (pull_request) Skipped
An app with no volume mounts now shows, in its Volume Mounts section, that the files it writes are lost whenever a deploy or rollback replaces its container and that a restart keeps them. Each deploy of such an app writes the same sentence into its log, after the webhook payload and before the clone. The README says in one sentence that a deploy or rollback starts a new container that keeps only the files in the app's volume mounts. Model: opus-5-5
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package deploy_test
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sneak.berlin/go/upaas/internal/config"
|
|
"sneak.berlin/go/upaas/internal/database"
|
|
"sneak.berlin/go/upaas/internal/docker"
|
|
"sneak.berlin/go/upaas/internal/logger"
|
|
"sneak.berlin/go/upaas/internal/models"
|
|
"sneak.berlin/go/upaas/internal/service/deploy"
|
|
"sneak.berlin/go/upaas/internal/service/notify"
|
|
)
|
|
|
|
// deployLog deploys a new app, with one volume mount when withVolume is set,
|
|
// and returns the deploy's log. Docker is not connected, so the deploy fails
|
|
// at the git clone, after the start of its log is written.
|
|
func deployLog(t *testing.T, withVolume bool) string {
|
|
t.Helper()
|
|
|
|
log := logger.NewForTest(slog.New(slog.NewTextHandler(os.Stderr, nil)))
|
|
dataDir := t.TempDir()
|
|
cfg := &config.Config{DataDir: dataDir, HostDataDir: dataDir}
|
|
db := database.NewTestDatabase(t)
|
|
|
|
dockerClient, err := docker.New(nil, docker.Params{Logger: log, Config: cfg})
|
|
require.NoError(t, err)
|
|
|
|
notifySvc, err := notify.New(nil, notify.ServiceParams{Logger: log})
|
|
require.NoError(t, err)
|
|
|
|
svc, err := deploy.New(nil, deploy.ServiceParams{
|
|
Logger: log, Config: cfg, Database: db,
|
|
Docker: dockerClient, Notify: notifySvc,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
app := models.NewApp(db)
|
|
app.ID = "volumesapp-id"
|
|
app.Name = "volumesapp"
|
|
app.Branch = "main"
|
|
require.NoError(t, app.Save(ctx))
|
|
|
|
if withVolume {
|
|
volume := models.NewVolume(db)
|
|
volume.AppID = app.ID
|
|
volume.HostPath = "/srv/volumesapp"
|
|
volume.ContainerPath = "/data"
|
|
require.NoError(t, volume.Save(ctx))
|
|
}
|
|
|
|
err = svc.Deploy(ctx, app, nil, false)
|
|
require.ErrorIs(t, err, docker.ErrNotConnected)
|
|
|
|
deployments, err := app.GetDeployments(ctx, 1)
|
|
require.NoError(t, err)
|
|
require.Len(t, deployments, 1)
|
|
|
|
return deployments[0].Logs.String
|
|
}
|
|
|
|
func TestDeployLogSaysFilesAreLostOnlyWhenAppHasNoVolumes(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
logWithoutVolumes := deployLog(t, false)
|
|
assert.Equal(t, 1, strings.Count(logWithoutVolumes, deploy.NoVolumesWarning),
|
|
logWithoutVolumes)
|
|
|
|
assert.NotContains(t, deployLog(t, true), deploy.NoVolumesWarning)
|
|
}
|