Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Restructure and expand filter tests #512

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions tests/integration/query/simple/with_dockey_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

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

func TestQuerySimpleWithDocKeyFilter(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple query with basic filter (key by DocKey arg)",
Query: `query {
users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Age": uint64(21),
},
},
},
{
Description: "Simple query with basic filter (key by DocKey arg), no results",
Query: `query {
users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009g") {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Results: []map[string]interface{}{},
},
{
Description: "Simple query with basic filter (key by DocKey arg), partial results",
Query: `query {
users(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`),
(`{
"Name": "Bob",
"Age": 32
}`)},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Age": uint64(21),
},
},
},
}

for _, test := range tests {
executeTestCase(t, test)
}
}
125 changes: 125 additions & 0 deletions tests/integration/query/simple/with_dockeys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

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

func TestQuerySimpleWithDocKeysFilter(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple query with basic filter (single key by DocKeys arg)",
Query: `query {
users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Age": uint64(21),
},
},
},
{
Description: "Simple query with basic filter (single key by DocKeys arg), no results",
Query: `query {
users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009g"]) {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`)},
},
Results: []map[string]interface{}{},
},
{
Description: "Simple query with basic filter (duplicate key by DocKeys arg), partial results",
Query: `query {
users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"]) {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`),
(`{
"Name": "Bob",
"Age": 32
}`)},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Age": uint64(21),
},
},
},
{
Description: "Simple query with basic filter (multiple key by DocKeys arg), partial results",
Query: `query {
users(dockeys: ["bae-52b9170d-b77a-5887-b877-cbdbb99b009f", "bae-1378ab62-e064-5af4-9ea6-49941c8d8f94"]) {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`),
(`{
"Name": "Bob",
"Age": 32
}`),
(`{
"Name": "Jim",
"Age": 27
}`)},
},
Results: []map[string]interface{}{
{
"Name": "Jim",
"Age": uint64(27),
},
{
"Name": "John",
"Age": uint64(21),
},
},
},
}

for _, test := range tests {
executeTestCase(t, test)
}
}
3 changes: 3 additions & 0 deletions tests/integration/query/simple/with_filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# With filter integration tests

Dedicated directory for simple schema integration tests targeting filter stuff.
30 changes: 30 additions & 0 deletions tests/integration/query/simple/with_filter/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

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

var userCollectionGQLSchema = (`
type users {
Name: String
Age: Int
HeightM: Float
Verified: Boolean
}
`)

func executeTestCase(t *testing.T, test testUtils.QueryTestCase) {
testUtils.ExecuteQueryTestCase(t, userCollectionGQLSchema, []string{"users"}, test)
}
60 changes: 60 additions & 0 deletions tests/integration/query/simple/with_filter/with_and_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

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

func TestQuerySimpleWithIntGreaterThanAndIntLessThanFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with logical compound filter (and)",
Query: `query {
users(filter: {_and: [{Age: {_gt: 20}}, {Age: {_lt: 50}}]}) {
Name
Age
}
}`,
Docs: map[int][]string{
0: {
(`{
"Name": "John",
"Age": 21
}`),
(`{
"Name": "Bob",
"Age": 32
}`),
(`{
"Name": "Carlo",
"Age": 55
}`),
(`{
"Name": "Alice",
"Age": 19
}`)},
},
Results: []map[string]interface{}{
{
"Name": "Bob",
"Age": uint64(32),
},
{
"Name": "John",
"Age": uint64(21),
},
},
}

executeTestCase(t, test)
}
49 changes: 49 additions & 0 deletions tests/integration/query/simple/with_filter/with_eq_float_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package simple

import (
"testing"

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

func TestQuerySimpleWithFloatEqualsFilterBlock(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with basic float filter",
Query: `query {
users(filter: {HeightM: {_eq: 2.1}}) {
Name
HeightM
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"HeightM": 2.1
}`,
`{
"Name": "Bob",
"HeightM": 1.82
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "John",
"HeightM": float64(2.1),
},
},
}

executeTestCase(t, test)
}
Loading