This repository was archived by the owner on Jul 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathden_test.go
More file actions
68 lines (55 loc) · 1.81 KB
/
Copy pathden_test.go
File metadata and controls
68 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Smoke tests for the wrappers in den.go. Like the other *_test.go files
// in the den root, these exist so the root package shows non-zero
// coverage — without them no other test file imports `den`. The engine
// logic each wrapper delegates to is tested against `engine.X` in
// engine's own test suite.
package den_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/oliverandrich/den"
"github.com/oliverandrich/den/dentest"
"github.com/oliverandrich/den/document"
)
// Shared fixture types used across crud_test.go, query_test.go, and
// options_test.go too. Declared here so the den_test package has a single
// home for them.
type smokeAuthor struct {
document.Base
document.Tracked
Name string `json:"name" den:"index"`
}
type smokeBook struct {
document.Base
document.SoftDelete
Title string `json:"title" den:"index"`
Author den.Link[smokeAuthor] `json:"author"`
}
func TestDen_NewID(t *testing.T) {
id := den.NewID()
assert.Len(t, id, 26, "ULID strings are 26 Crockford base32 characters")
}
func TestDen_Meta(t *testing.T) {
db := dentest.MustOpen(t, &smokeAuthor{})
meta, err := den.Meta[smokeAuthor](db)
require.NoError(t, err)
assert.NotEmpty(t, meta.Name)
}
func TestDen_Open(t *testing.T) {
db := dentest.MustOpen(t, &smokeAuthor{})
ctx := context.Background()
// Open with a Backend obtained from an existing DB.
manual, err := den.Open(ctx, db.Backend())
require.NoError(t, err)
require.NotNil(t, manual)
}
func TestDen_DropStaleIndexes(t *testing.T) {
db := dentest.MustOpen(t, &smokeAuthor{})
ctx := context.Background()
// DryRun — no schema change actually fires.
res, err := den.DropStaleIndexes(ctx, db, den.DryRun())
require.NoError(t, err)
_ = res // result shape covered by engine tests.
}