detached d9532c9

test: add preview lifecycle integration test

Covers full Create→List→Extend→Get→Delete cycle and CleanupExpired
behaviour via fakeStore, exercising the Service end-to-end.
commit
d9532c91012577f757623524bcc7dfc4c935c4c4
author
brice · · 2026-03-19 05:12 UTC
committer
brice · · 2026-03-19 05:13 UTC
parent
ad3801f
signature
unsigned
1 file · +88 -0
A internal/usecase/auto/preview/integration_test.go +88 -0
@@ -0,0 +1,88 @@
1+package preview
2+
3+import (
4+ "context"
5+ "testing"
6+ "time"
7+
8+ "github.com/bnema/gordon/internal/domain"
9+ "github.com/stretchr/testify/assert"
10+ "github.com/stretchr/testify/require"
11+)
12+
13+func TestPreviewLifecycle_Integration(t *testing.T) {
14+ store := &fakeStore{}
15+ svc := NewService(store, 2*time.Second)
16+
17+ ctx := context.Background()
18+
19+ // Create
20+ svc.CreatePreview(ctx, CreatePreviewRequest{
21+ Name: "test-feat",
22+ Domain: "myapp--test-feat.example.com",
23+ BaseRoute: "myapp.example.com",
24+ Image: "myapp:preview-test-feat",
25+ HTTPS: true,
26+ PreviewConfig: domain.PreviewConfig{
27+ TTL: 2 * time.Second,
28+ Separator: "--",
29+ DataCopy: false,
30+ },
31+ })
32+
33+ // Verify created
34+ all, err := svc.List(ctx)
35+ require.NoError(t, err)
36+ require.Len(t, all, 1)
37+ assert.Equal(t, "test-feat", all[0].Name)
38+ assert.Equal(t, "myapp--test-feat.example.com", all[0].Domain)
39+ assert.Equal(t, "myapp.example.com", all[0].BaseRoute)
40+
41+ // Extend
42+ err = svc.Extend(ctx, "test-feat", 1*time.Hour)
43+ require.NoError(t, err)
44+
45+ p, err := svc.Get(ctx, "test-feat")
46+ require.NoError(t, err)
47+ assert.True(t, p.ExpiresAt.After(time.Now().Add(55*time.Minute)))
48+
49+ // Delete
50+ err = svc.Delete(ctx, "test-feat")
51+ require.NoError(t, err)
52+
53+ all, _ = svc.List(ctx)
54+ assert.Empty(t, all)
55+}
56+
57+func TestPreviewLifecycle_CleanupExpired(t *testing.T) {
58+ store := &fakeStore{}
59+ svc := NewService(store, 1*time.Millisecond)
60+
61+ ctx := context.Background()
62+
63+ // Create with very short TTL
64+ svc.CreatePreview(ctx, CreatePreviewRequest{
65+ Name: "short-lived",
66+ Domain: "myapp--short-lived.example.com",
67+ BaseRoute: "myapp.example.com",
68+ Image: "myapp:preview-short-lived",
69+ HTTPS: true,
70+ PreviewConfig: domain.PreviewConfig{
71+ TTL: 1 * time.Millisecond,
72+ Separator: "--",
73+ DataCopy: false,
74+ },
75+ })
76+
77+ // Wait for expiry
78+ time.Sleep(10 * time.Millisecond)
79+
80+ // Cleanup should find it
81+ expired := svc.CleanupExpired(ctx)
82+ assert.Len(t, expired, 1)
83+ assert.Equal(t, "short-lived", expired[0].Name)
84+
85+ // Should be gone
86+ all, _ := svc.List(ctx)
87+ assert.Empty(t, all)
88+}
@@ -0,0 +1,88 @@
1+package preview
2+
3+import (
4+ "context"
5+ "testing"
6+ "time"
7+
8+ "github.com/bnema/gordon/internal/domain"
9+ "github.com/stretchr/testify/assert"
10+ "github.com/stretchr/testify/require"
11+)
12+
13+func TestPreviewLifecycle_Integration(t *testing.T) {
14+ store := &fakeStore{}
15+ svc := NewService(store, 2*time.Second)
16+
17+ ctx := context.Background()
18+
19+ // Create
20+ svc.CreatePreview(ctx, CreatePreviewRequest{
21+ Name: "test-feat",
22+ Domain: "myapp--test-feat.example.com",
23+ BaseRoute: "myapp.example.com",
24+ Image: "myapp:preview-test-feat",
25+ HTTPS: true,
26+ PreviewConfig: domain.PreviewConfig{
27+ TTL: 2 * time.Second,
28+ Separator: "--",
29+ DataCopy: false,
30+ },
31+ })
32+
33+ // Verify created
34+ all, err := svc.List(ctx)
35+ require.NoError(t, err)
36+ require.Len(t, all, 1)
37+ assert.Equal(t, "test-feat", all[0].Name)
38+ assert.Equal(t, "myapp--test-feat.example.com", all[0].Domain)
39+ assert.Equal(t, "myapp.example.com", all[0].BaseRoute)
40+
41+ // Extend
42+ err = svc.Extend(ctx, "test-feat", 1*time.Hour)
43+ require.NoError(t, err)
44+
45+ p, err := svc.Get(ctx, "test-feat")
46+ require.NoError(t, err)
47+ assert.True(t, p.ExpiresAt.After(time.Now().Add(55*time.Minute)))
48+
49+ // Delete
50+ err = svc.Delete(ctx, "test-feat")
51+ require.NoError(t, err)
52+
53+ all, _ = svc.List(ctx)
54+ assert.Empty(t, all)
55+}
56+
57+func TestPreviewLifecycle_CleanupExpired(t *testing.T) {
58+ store := &fakeStore{}
59+ svc := NewService(store, 1*time.Millisecond)
60+
61+ ctx := context.Background()
62+
63+ // Create with very short TTL
64+ svc.CreatePreview(ctx, CreatePreviewRequest{
65+ Name: "short-lived",
66+ Domain: "myapp--short-lived.example.com",
67+ BaseRoute: "myapp.example.com",
68+ Image: "myapp:preview-short-lived",
69+ HTTPS: true,
70+ PreviewConfig: domain.PreviewConfig{
71+ TTL: 1 * time.Millisecond,
72+ Separator: "--",
73+ DataCopy: false,
74+ },
75+ })
76+
77+ // Wait for expiry
78+ time.Sleep(10 * time.Millisecond)
79+
80+ // Cleanup should find it
81+ expired := svc.CleanupExpired(ctx)
82+ assert.Len(t, expired, 1)
83+ assert.Equal(t, "short-lived", expired[0].Name)
84+
85+ // Should be gone
86+ all, _ := svc.List(ctx)
87+ assert.Empty(t, all)
88+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close