forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Labels
Description
To simplify and standardize data setup in integration and end-to-end tests, we should integrate support for test fixtures—structured, version-controlled YAML (or JSON) files that define initial database state (spaces, tuples, indexes, etc.) for test scenarios.
This will allow test authors to:
- Declare expected dataset declaratively (instead of writing repetitive
Insert/Replaceboilerplate) and will obsolete (or extend) old way ofInsertOnInstances - Reuse common setups across multiple test suites
- Reset cluster state reliably between tests
- Keep test logic focused on behavior, not data provisioning
Proposed Approach
Introduce a new testfixtures package (or extend test_helpers) that can:
- Load fixture files
- Parse them into typed Tarantool operations
- Optionally create spaces from schema in fixtures
- Apply them to a given
*tarantool.Connectionor*pool.ConnectionPool
(with or without space prefix for isolation) - Optionally clean up (truncate spaces) before or after.
Example
schema:
users:
format:
- {name: id, type: unsigned}
- {name: name, type: string}
- {name: role, type: string}
indexes:
primary:
type: TREE
unique: true
parts:
- {field: id, type: unsigned}
name:
type: TREE
unique: false
parts:
- {field: name, type: string}
options:
if_not_exists: true
sessions:
format:
- {name: id, type: string}
indexes:
primary:
type: TREE
unique: true
parts:
- {field: id, type: string}
spaces:
users:
- [1, "alice", "admin"]
- [2, "bob", "user"]
sessions:
- ["sess1", 1, 1700000000]// Load and apply fixtures
err := testfixtures.Load(conn, "fixtures/basic.yaml")
require.NoError(t, err)
// Now run test logic against pre-seeded data
user, err := getUserByID(conn, 1)
require.NoError(t, err)
assert.Equal(t, "alice", user.Name)