Skip to content

Commit

Permalink
Allow assertion of AddSchema results
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jun 27, 2024
1 parent d78b96a commit 06b501e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/integration/schema/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand All @@ -28,6 +29,16 @@ func TestSchemaSimpleCreatesSchemaGivenEmptyType(t *testing.T) {
Schema: `
type Users {}
`,
ExpectedResults: []client.CollectionDescription{
{
Name: immutable.Some("Users"),
Fields: []client.CollectionFieldDescription{
{
Name: request.DocIDFieldName,
},
},
},
},
},
testUtils.IntrospectionRequest{
Request: `
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ type SchemaUpdate struct {
// The schema update.
Schema string

// Optionally, the expected results.
//
// Each item will be compared individually, if ID, RootID, SchemaVersionID or Fields on the
// expected item are default they will not be compared with the actual.
//
// Assertions on Indexes and Sources will not distinguish between nil and empty (in order
// to allow their ommission in most cases).
ExpectedResults []client.CollectionDescription

// Any error expected from the action. Optional.
//
// String can be a partial, and the test will pass if an error is returned that
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,14 @@ func updateSchema(
action SchemaUpdate,
) {
for _, node := range getNodes(action.NodeID, s.nodes) {
_, err := node.AddSchema(s.ctx, action.Schema)
results, err := node.AddSchema(s.ctx, action.Schema)
expectedErrorRaised := AssertError(s.t, s.testCase.Description, err, action.ExpectedError)

assertExpectedErrorRaised(s.t, s.testCase.Description, action.ExpectedError, expectedErrorRaised)

if action.ExpectedResults != nil {
assertCollectionDescriptions(s, action.ExpectedResults, results)
}
}

// If the schema was updated we need to refresh the collection definitions.
Expand Down

0 comments on commit 06b501e

Please sign in to comment.