From 137de71a671d66cee68a28e713c5abb8b147a237 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Wed, 6 Mar 2024 19:38:14 -0500 Subject: [PATCH 1/3] Convert update doc tests to new framework --- .../query/one_to_many/with_cid_doc_id_test.go | 325 ++++++++++------- .../query/simple/with_cid_doc_id_test.go | 333 ++++++++++-------- 2 files changed, 377 insertions(+), 281 deletions(-) diff --git a/tests/integration/query/one_to_many/with_cid_doc_id_test.go b/tests/integration/query/one_to_many/with_cid_doc_id_test.go index c518010b60..c9dd0ff4ba 100644 --- a/tests/integration/query/one_to_many/with_cid_doc_id_test.go +++ b/tests/integration/query/one_to_many/with_cid_doc_id_test.go @@ -64,48 +64,68 @@ import ( // } func TestQueryOneToManyWithCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "One-to-many relation query from one side with cid and docID", - Request: `query { - Book ( - cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii" - docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" - ) { - name - author { - name - } + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author } - }`, - Docs: map[int][]string{ - //books - 0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d - `{ + + type Author { + name: String + age: Int + verified: Boolean + published: [Book] + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 0, + // bae-fd541c25-229e-5280-b44b-e5c2af3e374d + Doc: `{ "name": "Painted House", "rating": 4.9, "author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" }`, }, - //authors - 1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 - `{ + testUtils.CreateDoc{ + CollectionID: 1, + // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 + Doc: `{ "name": "John Grisham", "age": 65, "verified": true }`, }, - }, - Results: []map[string]any{ - { - "name": "Painted House", - "author": map[string]any{ - "name": "John Grisham", + testUtils.Request{ + Request: `query { + Book ( + cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii" + docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" + ) { + name + author { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "author": map[string]any{ + "name": "John Grisham", + }, + }, }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } // This test is for documentation reasons only. This is not @@ -113,165 +133,218 @@ func TestQueryOneToManyWithCidAndDocID(t *testing.T) { // parent creation without explicit child cid, which is also not tied // to parent state). func TestQueryOneToManyWithChildUpdateAndFirstCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "One-to-many relation query from one side with child update and parent cid and docID", - Request: `query { - Book ( - cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii", - docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" - ) { - name - author { - name - age - } + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author } - }`, - Docs: map[int][]string{ - //books - 0: { // bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d - `{ + + type Author { + name: String + age: Int + verified: Boolean + published: [Book] + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 0, + // bae-fd541c25-229e-5280-b44b-e5c2af3e374d + Doc: `{ "name": "Painted House", "rating": 4.9, "author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" }`, }, - //authors - 1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 - `{ + testUtils.CreateDoc{ + CollectionID: 1, + // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 + Doc: `{ "name": "John Grisham", "age": 65, "verified": true }`, }, - }, - Updates: map[int]map[int][]string{ - 1: { - 0: { - `{ - "age": 22 - }`, - }, + testUtils.UpdateDoc{ + CollectionID: 1, + Doc: `{ + "age": 22 + }`, }, - }, - Results: []map[string]any{ - { - "name": "Painted House", - "author": map[string]any{ - "name": "John Grisham", - "age": int64(22), + testUtils.Request{ + Request: `query { + Book ( + cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii", + docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" + ) { + name + author { + name + age + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "author": map[string]any{ + "name": "John Grisham", + "age": int64(22), + }, + }, }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQueryOneToManyWithParentUpdateAndFirstCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "One-to-many relation query from one side with parent update and parent cid and docID", - Request: `query { - Book ( - cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii", - docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" - ) { - name + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author } - }`, - Docs: map[int][]string{ - //books - 0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d - `{ + + type Author { + name: String + age: Int + verified: Boolean + published: [Book] + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 0, + // bae-fd541c25-229e-5280-b44b-e5c2af3e374d + Doc: `{ "name": "Painted House", "rating": 4.9, "author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" }`, }, - //authors - 1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 - `{ + testUtils.CreateDoc{ + CollectionID: 1, + // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 + Doc: `{ "name": "John Grisham", "age": 65, "verified": true }`, }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - `{ - "rating": 4.5 - }`, - }, + testUtils.UpdateDoc{ + CollectionID: 0, + Doc: `{ + "rating": 4.5 + }`, }, - }, - Results: []map[string]any{ - { - "name": "Painted House", - "rating": float64(4.9), - "author": map[string]any{ - "name": "John Grisham", + testUtils.Request{ + Request: `query { + Book ( + cid: "bafybeidshqlc7z2psrtfhmrarsxwxwwis6baxjrzs2x6mdmzsop6b7hnii", + docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" + ) { + rating + author { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "rating": float64(4.9), + "author": map[string]any{ + "name": "John Grisham", + }, + }, }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQueryOneToManyWithParentUpdateAndLastCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "One-to-many relation query from one side with parent update and parent cid and docID", - Request: `query { - Book ( - cid: "bafybeiefqhex3axofwy2gwdynhs6rijwrpkdpwy5fnqnzbk3e7iwcgvrqa", - docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" - ) { - name - rating - author { - name - } + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Book { + name: String + rating: Float + author: Author } - }`, - Docs: map[int][]string{ - //books - 0: { // bae-fd541c25-229e-5280-b44b-e5c2af3e374d - `{ + + type Author { + name: String + age: Int + verified: Boolean + published: [Book] + } + `, + }, + testUtils.CreateDoc{ + CollectionID: 0, + // bae-fd541c25-229e-5280-b44b-e5c2af3e374d + Doc: `{ "name": "Painted House", "rating": 4.9, "author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" }`, }, - //authors - 1: { // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 - `{ + testUtils.CreateDoc{ + CollectionID: 1, + // bae-41598f0c-19bc-5da6-813b-e80f14a10df3 + Doc: `{ "name": "John Grisham", "age": 65, "verified": true }`, }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - `{ - "rating": 4.5 - }`, - }, + testUtils.UpdateDoc{ + CollectionID: 0, + Doc: `{ + "rating": 4.5 + }`, }, - }, - Results: []map[string]any{ - { - "name": "Painted House", - "rating": float64(4.5), - "author": map[string]any{ - "name": "John Grisham", + testUtils.Request{ + Request: `query { + Book ( + cid: "bafybeiefqhex3axofwy2gwdynhs6rijwrpkdpwy5fnqnzbk3e7iwcgvrqa", + docID: "bae-b9b83269-1f28-5c3b-ae75-3fb4c00d559d" + ) { + rating + author { + name + } + } + }`, + Results: []map[string]any{ + { + "name": "Painted House", + "rating": float64(4.5), + "author": map[string]any{ + "name": "John Grisham", + }, + }, }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } diff --git a/tests/integration/query/simple/with_cid_doc_id_test.go b/tests/integration/query/simple/with_cid_doc_id_test.go index bd29a143d9..f19bc4e9fa 100644 --- a/tests/integration/query/simple/with_cid_doc_id_test.go +++ b/tests/integration/query/simple/with_cid_doc_id_test.go @@ -17,256 +17,279 @@ import ( ) func TestQuerySimpleWithInvalidCidAndInvalidDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with invalid cid and invalid docID", - Request: `query { + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.Request{ + Request: `query { Users ( cid: "any non-nil string value - this will be ignored", docID: "invalid docID" ) { - Name + name } }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 - }`, + ExpectedError: "invalid cid: selected encoding not supported", }, }, - ExpectedError: "invalid cid: selected encoding not supported", } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } // This test is for documentation reasons only. This is not // desired behaviour (should just return empty). func TestQuerySimpleWithUnknownCidAndInvalidDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with unknown cid and invalid docID", - Request: `query { + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.Request{ + Request: `query { Users ( cid: "bafybeid57gpbwi4i6bg7g357vwwyzsmr4bjo22rmhoxrwqvdxlqxcgaqvu", docID: "invalid docID" ) { - Name + name } }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 - }`, + ExpectedError: "failed to get block in blockstore: ipld: could not find", }, }, - ExpectedError: "failed to get block in blockstore: ipld: could not find", } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQuerySimpleWithCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with cid and docID", - Request: `query { + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.Request{ + Request: `query { Users ( - cid: "bafybeicojqe66grk564b2hns3zi6rhquqvugxj6wi4s6xk4e2gg65dzx5e", - docID: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f" + cid: "bafybeidzstxabh7qktq7pkmmxvpjbnwklxz3h5l6d425ldvjy65xvvuxu4", + docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { - Name + name } }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 - }`, - }, - }, - Results: []map[string]any{ - { - "Name": "John", + Results: []map[string]any{ + { + "name": "John", + }, + }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQuerySimpleWithUpdateAndFirstCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with (first) cid and docID", - Request: `query { - Users ( - cid: "bafybeicojqe66grk564b2hns3zi6rhquqvugxj6wi4s6xk4e2gg65dzx5e", - docID: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f" - ) { - Name - Age + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 + }, + testUtils.UpdateDoc{ + Doc: `{ + "name": "Johnn" }`, }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - // update to change age to 22 on document 0 - `{"Age": 22}`, - // then update it again to change age to 23 on document 0 - `{"Age": 23}`, + testUtils.Request{ + Request: `query { + Users ( + cid: "bafybeidzstxabh7qktq7pkmmxvpjbnwklxz3h5l6d425ldvjy65xvvuxu4", + docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" + ) { + name + } + }`, + Results: []map[string]any{ + { + "name": "John", + }, }, }, }, - Results: []map[string]any{ - { - "Name": "John", - "Age": int64(21), - }, - }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQuerySimpleWithUpdateAndLastCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with (last) cid and docID", - Request: `query { - Users ( - cid: "bafybeifxz2k3qudz2fau37xu3unw5l4ihenha66tlb37gctq5mtdriq3ly" - docID: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f" - ) { - Name - Age + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 + }, + testUtils.UpdateDoc{ + Doc: `{ + "name": "Johnn" }`, }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - // update to change age to 22 on document 0 - `{"Age": 22}`, - // then update it again to change age to 23 on document 0 - `{"Age": 23}`, + testUtils.Request{ + Request: `query { + Users ( + cid: "bafybeickytibhqnqtwhpjfi7ponnu5756ifo76oxb2ksxrz4iiqaywg3lu", + docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" + ) { + name + } + }`, + Results: []map[string]any{ + { + "name": "Johnn", + }, }, }, }, - Results: []map[string]any{ - { - "Name": "John", - "Age": int64(23), - }, - }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQuerySimpleWithUpdateAndMiddleCidAndDocID(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with (middle) cid and docID", - Request: `query { - Users ( - cid: "bafybeigcjabzlkuj4j35boczgcl4jmars7gz5a7dfvpq3m344bzth7ebqq", - docID: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f" - ) { - Name - Age + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 + }, + testUtils.UpdateDoc{ + Doc: `{ + "name": "Johnn" }`, }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - // update to change age to 22 on document 0 - `{"Age": 22}`, - // then update it again to change age to 23 on document 0 - `{"Age": 23}`, - }, + testUtils.UpdateDoc{ + Doc: `{ + "name": "Johnnn" + }`, }, - }, - Results: []map[string]any{ - { - "Name": "John", - "Age": int64(22), + testUtils.Request{ + Request: `query { + Users ( + cid: "bafybeickytibhqnqtwhpjfi7ponnu5756ifo76oxb2ksxrz4iiqaywg3lu", + docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" + ) { + name + } + }`, + Results: []map[string]any{ + { + "name": "Johnn", + }, + }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } func TestQuerySimpleWithUpdateAndFirstCidAndDocIDAndSchemaVersion(t *testing.T) { - test := testUtils.RequestTestCase{ + test := testUtils.TestCase{ Description: "Simple query with (first) cid and docID and yielded schema version", - Request: `query { - Users ( - cid: "bafybeicojqe66grk564b2hns3zi6rhquqvugxj6wi4s6xk4e2gg65dzx5e", - docID: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f" + Actions: []any{ + testUtils.SchemaUpdate{ + Schema: ` + type Users { + name: String + } + `, + }, + testUtils.CreateDoc{ + Doc: `{ + "name": "John" + }`, + }, + testUtils.UpdateDoc{ + Doc: `{ + "name": "Johnn" + }`, + }, + testUtils.Request{ + Request: `query { + Users ( + cid: "bafybeidzstxabh7qktq7pkmmxvpjbnwklxz3h5l6d425ldvjy65xvvuxu4", + docID: "bae-decf6467-4c7c-50d7-b09d-0a7097ef6bad" ) { - Name - Age + name _version { schemaVersionId } } }`, - Docs: map[int][]string{ - 0: { - `{ - "Name": "John", - "Age": 21 - }`, - }, - }, - Updates: map[int]map[int][]string{ - 0: { - 0: { - // update to change age to 22 on document 0 - `{"Age": 22}`, - // then update it again to change age to 23 on document 0 - `{"Age": 23}`, - }, - }, - }, - Results: []map[string]any{ - { - "Name": "John", - "Age": int64(21), - "_version": []map[string]any{ + Results: []map[string]any{ { - "schemaVersionId": "bafkreiekkppcdl573ru624wh3kwkmy2nhqzjsvqpu6jv5dgq2kidpnon4u", + "name": "John", + "_version": []map[string]any{ + { + "schemaVersionId": "bafkreiebcgze3rs6j3g7gu65dwskdg5fn3qby5c6nqffhbdkcy2l5bbvp4", + }, + }, }, }, }, }, } - executeTestCase(t, test) + testUtils.ExecuteTestCase(t, test) } // Note: Only the first CID is reproducible given the added entropy to the Counter CRDT type. From ba721f368d489761948678a0f9d971d84ef83ebe Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Wed, 6 Mar 2024 20:00:07 -0500 Subject: [PATCH 2/3] Remove old test Update property --- tests/integration/utils.go | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/integration/utils.go b/tests/integration/utils.go index f15ac8f0ef..b530f45920 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -22,10 +22,6 @@ type RequestTestCase struct { // of docs in stringified JSON format Docs map[int][]string - // updates is a map from document index, to a list - // of changes in strinigied JSON format - Updates map[int]map[int][]string - Results []map[string]any // The expected content of an expected error @@ -56,21 +52,6 @@ func ExecuteRequestTestCase( } } - for collectionIndex, docUpdates := range test.Updates { - for docIndex, docs := range docUpdates { - for _, doc := range docs { - actions = append( - actions, - UpdateDoc{ - CollectionID: collectionIndex, - DocID: docIndex, - Doc: doc, - }, - ) - } - } - } - if test.Request != "" { actions = append( actions, From 72a7f588435aa013a9aead2aadc0134ad2d55c15 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Thu, 7 Mar 2024 09:52:06 -0500 Subject: [PATCH 3/3] PR FIXUP - Doc test change --- docs/data_format_changes/i2386-no-change-tests-updated.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/data_format_changes/i2386-no-change-tests-updated.md diff --git a/docs/data_format_changes/i2386-no-change-tests-updated.md b/docs/data_format_changes/i2386-no-change-tests-updated.md new file mode 100644 index 0000000000..c7940e2e1c --- /dev/null +++ b/docs/data_format_changes/i2386-no-change-tests-updated.md @@ -0,0 +1,3 @@ +# Convert old update tests to newer framework + +This is is not a breaking change, some test definitions were changed.