Skip to content

Commit

Permalink
test: Specify which collection to update in test framework (sourcenet…
Browse files Browse the repository at this point in the history
…work#601)

* Rename collectionIndex

cid suggests a CID, which is not what this is

* Rename documentIndex

Makes the difference between documentIndex and collectionIndex more obvious

* Specify which collection to update in test framework

And only update that collection
  • Loading branch information
AndrewSisley authored Jul 7, 2022
1 parent 13fb098 commit 8c9f58a
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 70 deletions.
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

0 comments on commit 8c9f58a

Please sign in to comment.