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: Specify which collection to update in test framework #601

Merged
merged 3 commits into from
Jul 7, 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
14 changes: 8 additions & 6 deletions tests/integration/mutation/relation/delete/single_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,14 @@ func TestRelationalDeletionOfADocumentUsingSingleKey_Success(t *testing.T) {
}`),
},
},
Updates: map[int][]string{
0: {
`{
"name": "Teiva Harsanyiiiiiiiiii",
"age": 49
}`,
Updates: map[int]map[int][]string{
1: {
0: {
`{
"name": "Teiva Harsanyiiiiiiiiii",
"age": 49
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ func TestExplainDeletionUsingMultiAndSingleIDs_Success(t *testing.T) {
},
},

Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
(`{
"age": 27,
"points": 48.2,
"verified": false
}`),
0: {
`{
"age": 27,
"points": 48.2,
"verified": false
}`,
},
},
},

Expand Down
14 changes: 8 additions & 6 deletions tests/integration/mutation/simple/delete/multi_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ func TestDeletionOfMultipleDocumentUsingMultipleKeys_Success(t *testing.T) {
}`),
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
(`{
"age": 27,
"points": 48.2,
"verified": false
}`),
0: {
`{
"age": 27,
"points": 48.2,
"verified": false
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down
14 changes: 8 additions & 6 deletions tests/integration/mutation/simple/delete/single_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ func TestDeletionOfADocumentUsingSingleKey_Success(t *testing.T) {
}`),
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
(`{
"age": 27,
"points": 48.2,
"verified": false
}`),
0: {
`{
"age": 27,
"points": 48.2,
"verified": false
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down
18 changes: 12 additions & 6 deletions tests/integration/query/all_commits/with_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ func TestQueryAllCommitsWithDockeyAndUpdate(t *testing.T) {
}`,
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
// update to change age to 22 on document 0
(`{"Age": 22}`),
0: {
`{
"Age": 22
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down Expand Up @@ -165,10 +168,13 @@ func TestQueryAllCommitsWithDockeyAndUpdateAndLinks(t *testing.T) {
}`,
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
// update to change age to 22 on document 0
(`{"Age": 22}`),
0: {
`{
"Age": 22
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down
29 changes: 19 additions & 10 deletions tests/integration/query/one_to_many/with_cid_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ func TestQueryOneToManyWithChildUpdateAndFirstCidAndDocKey(t *testing.T) {
"verified": true
}`)},
},
Updates: map[int][]string{
0: {
// update to change age to 22 on document 0, collection 1
`{"age": 22}`,
Updates: map[int]map[int][]string{
1: {
0: {
`{
"age": 22
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down Expand Up @@ -194,10 +197,13 @@ func TestQueryOneToManyWithParentUpdateAndFirstCidAndDocKey(t *testing.T) {
"verified": true
}`)},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
// update to change age to 22 on document 0, collection 0
`{"rating": 4.5}`,
0: {
`{
"rating": 4.5
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down Expand Up @@ -245,10 +251,13 @@ func TestQueryOneToManyWithParentUpdateAndLastCidAndDocKey(t *testing.T) {
"verified": true
}`)},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
0: {
// update to change age to 22 on document 0, collection 0
`{"rating": 4.5}`,
0: {
`{
"rating": 4.5
}`,
},
},
},
Results: []map[string]interface{}{
Expand Down
36 changes: 21 additions & 15 deletions tests/integration/query/simple/with_cid_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ func TestQuerySimpleWithUpdateAndFirstCidAndDocKey(t *testing.T) {
}`,
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
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}`,
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]interface{}{
Expand Down Expand Up @@ -156,12 +158,14 @@ func TestQuerySimpleWithUpdateAndLastCidAndDocKey(t *testing.T) {
}`,
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
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}`,
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]interface{}{
Expand Down Expand Up @@ -195,12 +199,14 @@ func TestQuerySimpleWithUpdateAndMiddleCidAndDocKey(t *testing.T) {
}`,
},
},
Updates: map[int][]string{
Updates: map[int]map[int][]string{
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}`,
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]interface{}{
Expand Down
33 changes: 18 additions & 15 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type QueryTestCase struct {

// updates is a map from document index, to a list
// of changes in strinigied JSON format
Updates map[int][]string
Updates map[int]map[int][]string
Results []map[string]interface{}
// The expected content of an expected error
ExpectedError string
Expand Down Expand Up @@ -479,28 +479,31 @@ func setupDatabase(
}

// insert docs
for cid, docs := range test.Docs {
for i, docStr := range docs {
for collectionIndex, docs := range test.Docs {
collectionUpdates, hasCollectionUpdates := test.Updates[collectionIndex]
for documentIndex, docStr := range docs {
doc, err := client.NewDocFromJSON([]byte(docStr))
if assertError(t, test.Description, err, test.ExpectedError) {
return
}
err = collections[cid].Save(ctx, doc)
err = collections[collectionIndex].Save(ctx, doc)
if assertError(t, test.Description, err, test.ExpectedError) {
return
}

// check for updates
updates, ok := test.Updates[i]
if ok {
for _, u := range updates {
err = doc.SetWithJSON([]byte(u))
if assertError(t, test.Description, err, test.ExpectedError) {
return
}
err = collections[cid].Save(ctx, doc)
if assertError(t, test.Description, err, test.ExpectedError) {
return
if hasCollectionUpdates {
documentUpdates, hasDocumentUpdates := collectionUpdates[documentIndex]

if hasDocumentUpdates {
for _, u := range documentUpdates {
err = doc.SetWithJSON([]byte(u))
if assertError(t, test.Description, err, test.ExpectedError) {
return
}
err = collections[collectionIndex].Save(ctx, doc)
if assertError(t, test.Description, err, test.ExpectedError) {
return
}
}
}
}
Expand Down