Documentation
¶
Overview ¶
Package dbtest provides minimal DB+model test helpers without depending on auth/capability/share — so it is safe to import from the test files of those packages without creating an import cycle.
If you need a full HTTP server harness (auth wiring, share service, capability probes), use internal/testutil instead.
Index ¶
- Constants
- func ApproveE2E(t *testing.T, store db.Store, userID, storageID int64, path, kind string) *model.E2ERequest
- func E2EStatus(t *testing.T, store db.Store, id int64) string
- func NewTestDB(t *testing.T) (*sql.DB, db.Store)
- func ReadJSON(t *testing.T, resp *http.Response, out any)
- func SeedAdmin(t *testing.T, store db.Store) (string, string)
- func SeedCatalogue(t testing.TB, store db.Store, storageID int64, root string, ...) int
- func SeedEmptyFolders(t testing.TB, store db.Store, storageID int64, root string, n int) int
- func SeedRegularUser(t *testing.T, store db.Store, email, password string)
- func SeedUserWithRole(t *testing.T, store db.Store, email, password, role string) int64
- func SettingFails(store db.Store, key string, err error) db.Store
- func TmpFilePath(t *testing.T, name string) string
- type VaultSeed
Constants ¶
const VaultKeyFile = `` /* 157-byte string literal not displayed */
VaultKeyFile is a vault's key file as the format reads it (docs/E2E-VAULT-FORMAT.md → The key file): v 3, req ["vault"], a wrapped folder key, packs of 2^22 bytes. Its slots open nothing: the doors under test never decrypt.
Variables ¶
This section is empty.
Functions ¶
func ApproveE2E ¶ added in v0.51.0
func ApproveE2E(t *testing.T, store db.Store, userID, storageID int64, path, kind string) *model.E2ERequest
ApproveE2E leaves what the requests service leaves when an administrator approves userID's request to encrypt as kind (model.E2ERequestFolder or E2ERequestFile) at path on storageID: an approved row, good for a day. path is where the rule looks for it (e2epolicy.ApprovalPath): the folder itself for an encrypted folder, the folder a `.fxe` goes into for a file.
func E2EStatus ¶ added in v0.51.0
E2EStatus is request id's status now: approved until a create spends it, used after.
func NewTestDB ¶
NewTestDB opens an in-memory SQLite DB, runs all migrations, and returns the underlying *sql.DB plus a typed Store. Cleanup is registered via t.Cleanup so tests don't have to remember to close.
func SeedAdmin ¶
SeedAdmin creates an admin user with a known password and returns the (email, plaintext password) tuple suitable for downstream login helpers.
func SeedCatalogue ¶ added in v0.52.0
func SeedCatalogue(t testing.TB, store db.Store, storageID int64, root string, tops, subs, files int, shuffled bool) int
SeedCatalogue catalogues a tree the shape of a real one on storageID - root, tops folders in it ("Müşteri-NN"), subs folders in each ("Sözleşmeler-NN") and files files in each of those ("belge-NNN.pdf") - and returns the number of rows written. It is for the tests that measure the catalogue at the size of an install (`-tags measure`): rows as wide as a sync writes them, 2,500 to a transaction.
The rows are written in path order, as a first sync walks a storage, unless shuffled: then in an order that has nothing to do with their paths (always the same one), as a catalogue ends up after years of uploads and moves. The two differ for every question that reads many rows through an index on path: in path order the rows of a folder sit side by side in the table.
func SeedEmptyFolders ¶ added in v0.52.0
SeedEmptyFolders catalogues root and n folders in it ("klasör-NNNN") with nothing below them, and returns the number of rows written.
func SeedRegularUser ¶
SeedRegularUser creates a non-admin user with the supplied credentials.
func SeedUserWithRole ¶
SeedUserWithRole creates a user with an explicit role and returns the generated user ID. Useful when tests need a specific role beyond the two helpers above.
func SettingFails ¶ added in v0.51.0
SettingFails is store with one setting that cannot be read: GetSetting(key) answers err, and everything else is store's own. It is how a test makes a decision that reads a setting (e2e.policy, say) undecidable.
Types ¶
type VaultSeed ¶ added in v0.54.0
type VaultSeed struct {
Root string // the vault folder
KeyFile string
Index string // generation 1's index file
Pack string // one pack
}
VaultSeed names what SeedVault put in place, relative to the storage.
func SeedVault ¶ added in v0.54.0
SeedVault puts a vault at rel on a local storage whose root is dir: its key file, generation 1's index file and one pack (its header only - the doors under test read no further), on disk and in the catalogue. The catalogue rows matter: the vault rule finds a vault by its key file's row (vaultlock.Finder), as every door's writegate check does.