Skip to content

Commit

Permalink
refactor: Migrate gql introspection tests to new framework (#1211)
Browse files Browse the repository at this point in the history
* Use reflect for action bundling

The code is shorter but more complex.  Importantly it means that we do not need to remember to add new action types to 3 code locations (len calc, flatten, main-loop) within the framework, something that is error prone and a bit of a hassle.

* Add gql introspection support to test framework

Code is copy-pasted from existing schema/utils.go file, plus a couple of compilation tweaks and var renames.

* Migrate client_test.go to new framework

No changes to test content

* Migrate filter_test.go to new framework

No changes to test contents

* Migrate input_type_test.go to new framework

No changes to test contents

* Migrate simple_test.go to new framework

Due to differences in error handling some of these tests have changed slightly. In the old introspection tests, `ExpectedErrrors` would be compared against errrors generated during schema update, and during introspection - the new framework ties an expected error to a specific action.  For these tests it is now clear that the errors occur on schema update, and not during introspection.  This means that in the original, the introspection query was declared but never actually run (test would exist early on expected error), as such this commit also removes the declaration of these never-executed introspection queries.

* Migrate with_inline_array_test.go to new framework

No changes to test contents

* Migrate inline_array_test.go to new framework

No changes to test contents

* Migrate simple_test.go to new framework

No changes to test contents

* Migrate top_level_test.go to new framework

No changes to test contents

* Remove old test utils
  • Loading branch information
AndrewSisley authored and shahzadlone committed Apr 13, 2023
1 parent 150c2a5 commit 60e8f90
Show file tree
Hide file tree
Showing 11 changed files with 2,141 additions and 2,149 deletions.
2,178 changes: 1,111 additions & 1,067 deletions tests/integration/schema/aggregates/inline_array_test.go

Large diffs are not rendered by default.

424 changes: 218 additions & 206 deletions tests/integration/schema/aggregates/simple_test.go

Large diffs are not rendered by default.

396 changes: 204 additions & 192 deletions tests/integration/schema/aggregates/top_level_test.go

Large diffs are not rendered by default.

44 changes: 24 additions & 20 deletions tests/integration/schema/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,40 @@ import (
"testing"

schemaTypes "github.com/sourcenetwork/defradb/request/graphql/schema/types"
testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

// TestIntrospectionExplainTypeDefined tests that the introspection query returns a schema that
// defines the ExplainType enum.
func TestIntrospectionExplainTypeDefined(t *testing.T) {
test := RequestTestCase{
Schema: []string{},
IntrospectionRequest: `
query IntrospectionQuery {
__schema {
types {
kind
name
description
test := testUtils.TestCase{
Actions: []any{
testUtils.IntrospectionRequest{
Request: `
query IntrospectionQuery {
__schema {
types {
kind
name
description
}
}
}
}
}
`,
ContainsData: map[string]any{
"__schema": map[string]any{
"types": []any{
map[string]any{
"description": schemaTypes.ExplainEnum.Description(),
"kind": "ENUM",
"name": "ExplainType",
`,
ContainsData: map[string]any{
"__schema": map[string]any{
"types": []any{
map[string]any{
"description": schemaTypes.ExplainEnum.Description(),
"kind": "ENUM",
"name": "ExplainType",
},
},
},
},
},
},
}

ExecuteRequestTestCase(t, test)
testUtils.ExecuteTestCase(t, []string{}, test)
}
Loading

0 comments on commit 60e8f90

Please sign in to comment.