check / check (push) Waiting to run
For a database target, the target list showed only its expiry, so the archive file the README's backup and move-away advice depend on could only be found from a shell on the host. Each database target now shows its archive file's name, its size on disk (the file and its -wal together) and when it was last written, relative with the full UTC time on hover, all from the files' metadata without opening the archive. Before the first write, and after the file has been moved away, it shows the name and "not created yet". Tests cover all three states. Model: opus-5-5
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package handlers_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
"sneak.berlin/go/webhooker/internal/delivery"
|
|
"sneak.berlin/go/webhooker/internal/handlers"
|
|
"sneak.berlin/go/webhooker/internal/session"
|
|
)
|
|
|
|
// TestHandleSourceDetail_ShowsArchiveFile proves a database target's
|
|
// row names its archive file and says "not created yet" before the
|
|
// first write, adds the file's size and last write once it has one row,
|
|
// and says "not created yet" again once the file has been moved away.
|
|
// A target of another type shows no archive file.
|
|
func TestHandleSourceDetail_ShowsArchiveFile(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var (
|
|
h *handlers.Handlers
|
|
sess *session.Session
|
|
db *database.Database
|
|
dbMgr *database.WebhookDBManager
|
|
)
|
|
|
|
app := newTestApp(t, &h, &sess, &db, &dbMgr)
|
|
app.RequireStart()
|
|
|
|
t.Cleanup(app.RequireStop)
|
|
|
|
wh := seedWebhook(t, db)
|
|
archive := seedTarget(t, db, wh.ID, database.TargetTypeDatabase)
|
|
seedTarget(t, db, wh.ID, database.TargetTypeLog)
|
|
|
|
path := delivery.ArchivePath(dbMgr, wh, archive)
|
|
|
|
body := renderSourceDetailPage(t, h, sess, wh.ID)
|
|
assert.Equal(t, 1, strings.Count(body, "Archive File:"))
|
|
assert.Contains(t, body, filepath.Base(path))
|
|
assert.Contains(t, body, "not created yet")
|
|
assert.NotContains(t, body, "Archive Size:")
|
|
|
|
seedArchive(t, path, 1, 100)
|
|
|
|
file, err := os.Stat(path)
|
|
require.NoError(t, err)
|
|
|
|
body = renderSourceDetailPage(t, h, sess, wh.ID)
|
|
assert.Contains(t, body, filepath.Base(path))
|
|
assert.NotContains(t, body, "not created yet")
|
|
assert.Regexp(t,
|
|
`Archive Size:</span>\s*<span>[1-9][0-9.]* [kM]?B</span>`, body,
|
|
)
|
|
assert.Contains(t, body,
|
|
`title="`+file.ModTime().UTC().Format(time.DateTime)+` UTC"`,
|
|
)
|
|
|
|
require.NoError(t, os.Rename(path, filepath.Join(t.TempDir(), "moved.db")))
|
|
|
|
body = renderSourceDetailPage(t, h, sess, wh.ID)
|
|
assert.Contains(t, body, filepath.Base(path))
|
|
assert.Contains(t, body, "not created yet")
|
|
assert.NotContains(t, body, "Archive Size:")
|
|
}
|