defradb
defradb copied to clipboard
Integrate sub-tests into integration test framework
A good number of our tests use large blocks of repetitive data that causes copy-paste readability issues as well as wasting computing resources when performing multiple times.
We can hide the Go test syntax and other ugliness behind out test harness (https://go.dev/blog/subtests).
It is important that it is easy to run specific sub-tests, we wish to avoid the annoying situation where sub-tests must be commented out in order to run a single sub-test (use of the SubTest.Name
property in the example, or similar, should hopefully allow this).
This may increase the likelihood of us needlessly coupling tests together, and the likelihood of writing tests that depend on state caused by a previous (we can perhaps randomise the order in which sub-tests execute to reduce this last problem).
For example, a test may look something like:
test := testUtils.TestCase{
Description: "Combination of a filter on regular and of an indexed field",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String @index
verified: Boolean
}`,
},
testUtils.CreateDoc{
Doc: `{
"name": "John",
"verified": true
}`,
},
},
SubTests: []testUtils.SubTest{
{
Name: "Test name",
Actions: []any{
testUtils.Request{
Request: `query {
Users {
name
}
}`,
Results: []map[string]any{
{
"name": "John",
},
},
},
},
},
{
Name: "Test verified",
Actions: []any{
testUtils.Request{
Request: `query {
Users {
verified
}
}`,
Results: []map[string]any{
{
"verified": true,
},
},
},
},
},
},
}
The SchemaUpdate
and CreateDoc
would be run once, followed by the two sub tests (both Request
s).
Idea voiced by Fred in our one-one, I'm just writing it up because I want a ticket for it.