(t *testing.T)
| 465 | } |
| 466 | |
| 467 | func TestBackupHookBehavior(t *testing.T) { |
| 468 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
| 469 | defer cancel() |
| 470 | |
| 471 | ns, err := docker.NewNamespace("once-backup-hook-test") |
| 472 | require.NoError(t, err) |
| 473 | defer ns.Teardown(ctx, true) |
| 474 | |
| 475 | require.NoError(t, ns.EnsureNetwork(ctx)) |
| 476 | require.NoError(t, ns.Proxy().Boot(ctx, getProxyPorts(t))) |
| 477 | |
| 478 | app := deployApp(t, ctx, ns, docker.ApplicationSettings{ |
| 479 | Name: "hooktest", |
| 480 | Image: "ghcr.io/basecamp/once-campfire:main", |
| 481 | Host: "hooktest.localhost", |
| 482 | }) |
| 483 | |
| 484 | containerName, err := app.ContainerName(ctx) |
| 485 | require.NoError(t, err) |
| 486 | |
| 487 | backupDir := t.TempDir() |
| 488 | |
| 489 | t.Run("WithoutHook", func(t *testing.T) { |
| 490 | stop := collectPauseEvents(t, ctx, containerName) |
| 491 | require.NoError(t, app.BackupToFile(ctx, backupDir, "no-hook.tar.gz")) |
| 492 | actions := stop() |
| 493 | assert.Contains(t, actions, "pause") |
| 494 | assert.Contains(t, actions, "unpause") |
| 495 | }) |
| 496 | |
| 497 | t.Run("WithSuccessfulHook", func(t *testing.T) { |
| 498 | copyHookToContainer(t, ctx, containerName, "pre-backup", []byte("#!/bin/sh\nexit 0")) |
| 499 | |
| 500 | stop := collectPauseEvents(t, ctx, containerName) |
| 501 | require.NoError(t, app.BackupToFile(ctx, backupDir, "successful-hook.tar.gz")) |
| 502 | actions := stop() |
| 503 | assert.Empty(t, actions) |
| 504 | }) |
| 505 | |
| 506 | t.Run("WithFailedHook", func(t *testing.T) { |
| 507 | copyHookToContainer(t, ctx, containerName, "pre-backup", []byte("#!/bin/sh\nexit 1")) |
| 508 | |
| 509 | stop := collectPauseEvents(t, ctx, containerName) |
| 510 | require.NoError(t, app.BackupToFile(ctx, backupDir, "failed-hook.tar.gz")) |
| 511 | actions := stop() |
| 512 | assert.Contains(t, actions, "pause") |
| 513 | assert.Contains(t, actions, "unpause") |
| 514 | }) |
| 515 | } |
| 516 | |
| 517 | func TestBackupStoppedContainer(t *testing.T) { |
| 518 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
nothing calls this directly
no test coverage detected
searching dependent graphs…