this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(store): add simple test case

to ensure our chain continues to work.

authored by

Till Klampaeckel and committed by
Tangled
3ce22933 f0ec537c

+69
+3
.tangled/workflows/ci.yml
··· 18 18 19 19 - name: build 20 20 command: make build 21 + 22 + - name: test 23 + command: make test
+3
Makefile
··· 12 12 generate: 13 13 go generate ./ent/... 14 14 15 + test: 16 + go test -v --race ./... 17 + 15 18 vet: 16 19 go vet ./... 17 20
+3
go.mod
··· 7 7 github.com/benbjohnson/litestream v0.5.11 8 8 github.com/bluesky-social/indigo v0.0.0-20260428083920-ce62b8fce9e0 9 9 github.com/bluesky-social/jetstream v0.0.0-20260415170838-8a65de4eda28 10 + github.com/stretchr/testify v1.11.1 10 11 modernc.org/sqlite v1.44.3 11 12 ) 12 13 ··· 37 38 github.com/beorn7/perks v1.0.1 // indirect 38 39 github.com/bmatcuk/doublestar v1.3.4 // indirect 39 40 github.com/cespare/xxhash/v2 v2.3.0 // indirect 41 + github.com/davecgh/go-spew v1.1.1 // indirect 40 42 github.com/earthboundkid/versioninfo/v2 v2.24.1 // indirect 41 43 github.com/felixge/httpsnoop v1.0.4 // indirect 42 44 github.com/go-logr/logr v1.4.1 // indirect ··· 82 84 github.com/multiformats/go-varint v0.0.7 // indirect 83 85 github.com/opentracing/opentracing-go v1.2.0 // indirect 84 86 github.com/pierrec/lz4/v4 v4.1.22 // indirect 87 + github.com/pmezard/go-difflib v1.0.0 // indirect 85 88 github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect 86 89 github.com/prometheus/client_golang v1.19.1 // indirect 87 90 github.com/prometheus/client_model v0.6.1 // indirect
+60
store/store_test.go
··· 1 + package store_test 2 + 3 + import ( 4 + "database/sql" 5 + "testing" 6 + 7 + "entgo.io/ent/dialect" 8 + entsql "entgo.io/ent/dialect/sql" 9 + 10 + "github.com/stretchr/testify/assert" 11 + "github.com/stretchr/testify/require" 12 + 13 + _ "modernc.org/sqlite" 14 + 15 + "tangled.sh/chown.de/tangled-repo-firehose/ent" 16 + "tangled.sh/chown.de/tangled-repo-firehose/ent/enttest" 17 + ) 18 + 19 + // TestSchema migrates the Ent schema into an in-memory SQLite and 20 + // round-trips a Repo through it. 21 + func TestSchema(t *testing.T) { 22 + db := sqlOpen(t) 23 + t.Cleanup(func() { _ = db.Close() }) 24 + 25 + drv := entsql.OpenDB(dialect.SQLite, db) 26 + client := enttest.NewClient(t, enttest.WithOptions(ent.Driver(drv))) 27 + t.Cleanup(func() { _ = client.Close() }) 28 + 29 + ctx := t.Context() 30 + 31 + const atURI = "at://did:plc:test/sh.tangled.repo/abc" 32 + if _, err := client.Repo.Create(). 33 + SetID(atURI). 34 + SetDid("did:plc:test"). 35 + SetRkey("abc"). 36 + SetName("demo"). 37 + SetKnot("knot.example.org"). 38 + SetCreatedAt(1). 39 + SetSeenAt(2). 40 + Save(ctx); err != nil { 41 + t.Fatalf("Repo.Create: %v", err) 42 + } 43 + 44 + got, err := client.Repo.Get(ctx, atURI) 45 + require.NoError(t, err) 46 + 47 + assert.Equal(t, "demo", got.Name) 48 + assert.Equal(t, "knot.example.org", got.Knot) 49 + 50 + n, err := client.Repo.Query().Count(ctx) 51 + require.NoError(t, err) 52 + assert.Equal(t, 1, n, "Repo.Count") 53 + } 54 + 55 + func sqlOpen(t *testing.T) *sql.DB { 56 + t.Helper() 57 + db, err := sql.Open("sqlite", ":memory:?_pragma=foreign_keys(1)") 58 + require.NoError(t, err) 59 + return db 60 + }