-
Notifications
You must be signed in to change notification settings - Fork 46
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 cid (time-travel) query tests #539
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
266 changes: 266 additions & 0 deletions
266
tests/integration/query/one_to_many/with_cid_dockey_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
// 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 one_to_many | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
// This test is for documentation reasons only. I do not see this | ||
// as desired behaviour (should just return empty). | ||
func TestQueryOneToManyWithUnknownCidAndDocKey(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "One-to-many relation query from one side with unknown cid and dockey", | ||
Query: `query { | ||
book ( | ||
cid: "bafybeihtn2xjbjjqxeqp2uhwhvk3tmjfkaf2qtfqh5w5q3ews7ax2dc75a", | ||
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" | ||
) { | ||
name | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`)}, | ||
//authors | ||
1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"author": map[string]interface{}{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
assert.Panics(t, func() { | ||
executeTestCase(t, test) | ||
}) | ||
} | ||
|
||
func TestQueryOneToManyWithCidAndDocKey(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "One-to-many relation query from one side with cid and dockey", | ||
Query: `query { | ||
book ( | ||
cid: "bafybeigcxmx2mbkmmkujm6vv4eoa57vfg2a22sum4p46empn6fcqkzpdma", | ||
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" | ||
) { | ||
name | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`)}, | ||
//authors | ||
1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`)}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"author": map[string]interface{}{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
// This test is for documentation reasons only. I do not see this | ||
// as desired behaviour (no way to get state of child a time of | ||
// parent creation without explicit child cid, which is also not tied | ||
// to parent state). | ||
func TestQueryOneToManyWithChildUpdateAndFirstCidAndDocKey(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "One-to-many relation query from one side with child update and parent cid and dockey", | ||
Query: `query { | ||
book ( | ||
cid: "bafybeigcxmx2mbkmmkujm6vv4eoa57vfg2a22sum4p46empn6fcqkzpdma", | ||
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" | ||
) { | ||
name | ||
author { | ||
name | ||
age | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`)}, | ||
//authors | ||
1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`)}, | ||
}, | ||
Updates: map[int][]string{ | ||
0: { | ||
// update to change age to 22 on document 0, collection 1 | ||
`{"age": 22}`, | ||
}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"author": map[string]interface{}{ | ||
"name": "John Grisham", | ||
"age": uint64(22), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQueryOneToManyWithParentUpdateAndFirstCidAndDocKey(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "One-to-many relation query from one side with parent update and parent cid and dockey", | ||
Query: `query { | ||
book ( | ||
cid: "bafybeigcxmx2mbkmmkujm6vv4eoa57vfg2a22sum4p46empn6fcqkzpdma", | ||
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" | ||
) { | ||
name | ||
rating | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`)}, | ||
//authors | ||
1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`)}, | ||
}, | ||
Updates: map[int][]string{ | ||
0: { | ||
// update to change age to 22 on document 0, collection 0 | ||
`{"rating": 4.5}`, | ||
}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"rating": float64(4.9), | ||
"author": map[string]interface{}{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} | ||
|
||
func TestQueryOneToManyWithParentUpdateAndLastCidAndDocKey(t *testing.T) { | ||
test := testUtils.QueryTestCase{ | ||
Description: "One-to-many relation query from one side with parent update and parent cid and dockey", | ||
Query: `query { | ||
book ( | ||
cid: "bafybeifc33ql7a5vna3epx55lm2dwyhmq7souodlhnsrfwhz6gfqcb6wje", | ||
dockey: "bae-fd541c25-229e-5280-b44b-e5c2af3e374d" | ||
) { | ||
name | ||
rating | ||
author { | ||
name | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`)}, | ||
//authors | ||
1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`)}, | ||
}, | ||
Updates: map[int][]string{ | ||
0: { | ||
// update to change age to 22 on document 0, collection 0 | ||
`{"rating": 4.5}`, | ||
}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"rating": float64(4.5), | ||
"author": map[string]interface{}{ | ||
"name": "John Grisham", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: As mentioned on discord, I don't think these kinds of queries should be supported yet, as the return document will violate the "Time travel" mechanic since the root document will be the target version (cid) but the sub document won't be.