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: Add tests for default properties #611

Merged
merged 3 commits into from
Jul 11, 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
8 changes: 4 additions & 4 deletions db/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ func (df *DocumentFetcher) ProcessKV(kv *core.KeyValue) error {

// nextKey gets the next kv. It sets both kv and kvEnd internally.
// It returns true if the current doc is completed
func (df *DocumentFetcher) nextKey(ctx context.Context) (docDone bool, err error) {
func (df *DocumentFetcher) nextKey(ctx context.Context) (spanDone bool, err error) {
// get the next kv from nextKV()
for {
docDone, df.kv, err = df.nextKV()
spanDone, df.kv, err = df.nextKV()
// handle any internal errors
if err != nil {
return false, err
Expand All @@ -213,10 +213,10 @@ func (df *DocumentFetcher) nextKey(ctx context.Context) (docDone bool, err error
if df.kv != nil && df.kv.Key.InstanceType != core.ValueKey {
// We can only ready value values, if we escape the collection's value keys
// then we must be done and can stop reading
docDone = true
spanDone = true
}

df.kvEnd = docDone
df.kvEnd = spanDone
if df.kvEnd {
hasNextSpan, err := df.startNextSpan(ctx)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions docs/data_format_changes/i412-no-change-tests-updated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add tests for default properties

This is is not a breaking change, but the test schema was updated which resulted in a few false-failures in the change-detector tool. Not relevent to defra users.
22 changes: 22 additions & 0 deletions tests/integration/query/inline_array/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ func TestQueryInlineArrayWithBooleans(t *testing.T) {

func TestQueryInlineArrayWithIntegers(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple inline array with no filter, default integer array",
Query: `query {
users {
Name
FavouriteIntegers
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John"
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "John",
"FavouriteIntegers": nil,
},
},
},
{
Description: "Simple inline array with no filter, nil integer array",
Query: `query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestQueryOneToManyWithUnknownCidAndDocKey(t *testing.T) {
Description: "One-to-many relation query from one side with unknown cid and dockey",
Query: `query {
book (
cid: "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a",
cid: "bafybeicgwjdyqyuntdop5ytpsfrqg5a4t2r25pfv6prfppl5ta5k5altca",
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d"
) {
name
Expand Down
58 changes: 58 additions & 0 deletions tests/integration/query/simple/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,61 @@ func TestQuerySimpleWithUndefinedField(t *testing.T) {

executeTestCase(t, test)
}

func TestQuerySimpleWithSomeDefaultValues(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with some default-value fields",
Query: `query {
users {
Name
Email
Age
HeightM
Verified
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John"
}`,
},
},
Results: []map[string]interface{}{
{
"Name": "John",
"Email": nil,
"Age": nil,
"HeightM": nil,
"Verified": nil,
},
},
}

executeTestCase(t, test)
}

// This test documents undesirable behaviour and should be altered
// with https://github.com/sourcenetwork/defradb/issues/610.
// A document with nil fields should be returned.
func TestQuerySimpleWithDefaultValue(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple query with default-value fields",
Query: `query {
users {
Name
Age
HeightM
Verified
}
}`,
Docs: map[int][]string{
0: {
`{ }`,
},
},
Results: []map[string]interface{}{},
Comment on lines +172 to +177
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though: The way I interpret this is that you add an empty object to the database which from the expected result tells me that an empty object will be discarded. Am I thinking about this right? Otherwise I would expect this to be the result:

{
	"Name":     nil,
	"Email":    nil,
	"Age":      nil,
	"HeightM":  nil,
	"Verified": nil,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - there is a comment linked to an issue regarding this at the top of the test function.

}

executeTestCase(t, test)
}
1 change: 1 addition & 0 deletions tests/integration/query/simple/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type dataMap = map[string]interface{}
var userCollectionGQLSchema = (`
type users {
Name: String
Email: String
Age: Int
HeightM: Float
Verified: Boolean
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/query/simple/with_cid_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestQuerySimpleWithCidAndDocKey(t *testing.T) {
Description: "Simple query with cid and dockey",
Query: `query {
users (
cid: "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a",
cid: "bafybeigriq4rcvsugsqiohxvtov2kvcmtqtldesobtx7vsjl556dhpliau",
dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
) {
Name
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestQuerySimpleWithUpdateAndFirstCidAndDocKey(t *testing.T) {
Description: "Simple query with (first) cid and dockey",
Query: `query {
users (
cid: "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a",
cid: "bafybeigriq4rcvsugsqiohxvtov2kvcmtqtldesobtx7vsjl556dhpliau",
dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
) {
Name
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestQuerySimpleWithUpdateAndLastCidAndDocKey(t *testing.T) {
Description: "Simple query with (last) cid and dockey",
Query: `query {
users (
cid: "bafybeiexy3vpswo6hzn6hw2ibw6rcsd6py5dxzcwxhr7rs7sd5jmzimo7q",
cid: "bafybeiehnzljzuijwsf474kwa2wdzptbiaxtszfgz2q4o3xnczfgwj22ei",
dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
) {
Name
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestQuerySimpleWithUpdateAndMiddleCidAndDocKey(t *testing.T) {
Description: "Simple query with (middle) cid and dockey",
Query: `query {
users (
cid: "bafybeif65sq3ajrocd5lieudu6lr6k4kufiiv3dbzn4qgtbal23hbnufwm",
cid: "bafybeiceb4p4bq7z3wrrr7q3jzsg44liuxvkov5xucxqwawx4hj6hx7tiy",
dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f"
) {
Name
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/query/simple/with_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func TestQuerySimpleWithEmbeddedLatestCommit(t *testing.T) {
"Age": uint64(21),
"_version": []map[string]interface{}{
{
"cid": "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a",
"cid": "bafybeigriq4rcvsugsqiohxvtov2kvcmtqtldesobtx7vsjl556dhpliau",
"links": []map[string]interface{}{
{
"cid": "bafybeidst2mzxhdoh4ayjdjoh4vibo7vwnuoxk3xgyk5mzmep55jklni2a",
"name": "Age",
},
{
"cid": "bafybeidkse2jiqekdebh6zdq4zvyx4gzyrupujbtb6gd7qqdb4hj3pyaeq",
"cid": "bafybeicgwjdyqyuntdop5ytpsfrqg5a4t2r25pfv6prfppl5ta5k5altca",
"name": "Name",
},
},
Expand Down Expand Up @@ -97,14 +97,14 @@ func TestQuerySimpleWithMultipleAliasedEmbeddedLatestCommit(t *testing.T) {
"Age": uint64(21),
"_version": []map[string]interface{}{
{
"cid": "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a",
"cid": "bafybeigriq4rcvsugsqiohxvtov2kvcmtqtldesobtx7vsjl556dhpliau",
"L1": []map[string]interface{}{
{
"cid": "bafybeidst2mzxhdoh4ayjdjoh4vibo7vwnuoxk3xgyk5mzmep55jklni2a",
"name": "Age",
},
{
"cid": "bafybeidkse2jiqekdebh6zdq4zvyx4gzyrupujbtb6gd7qqdb4hj3pyaeq",
"cid": "bafybeicgwjdyqyuntdop5ytpsfrqg5a4t2r25pfv6prfppl5ta5k5altca",
"name": "Name",
},
},
Expand Down