-
Notifications
You must be signed in to change notification settings - Fork 43
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 event tests #965
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,27 @@ | ||
// 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 simple | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration/events" | ||
) | ||
|
||
var schema = ` | ||
type users { | ||
Name: String | ||
} | ||
` | ||
|
||
func executeTestCase(t *testing.T, test testUtils.TestCase) { | ||
testUtils.ExecuteQueryTestCase(t, schema, test) | ||
} |
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,69 @@ | ||
// 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 simple | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
testUtils "github.com/sourcenetwork/defradb/tests/integration/events" | ||
) | ||
|
||
func TestEventsSimpleWithCreate(t *testing.T) { | ||
doc1, err := client.NewDocFromJSON( | ||
[]byte( | ||
`{ | ||
"Name": "John" | ||
}`, | ||
), | ||
) | ||
assert.Nil(t, err) | ||
docKey1 := doc1.Key().String() | ||
|
||
doc2, err := client.NewDocFromJSON( | ||
[]byte( | ||
`{ | ||
"Name": "Shahzad" | ||
}`, | ||
), | ||
) | ||
assert.Nil(t, err) | ||
docKey2 := doc2.Key().String() | ||
|
||
test := testUtils.TestCase{ | ||
CollectionCalls: map[string][]func(client.Collection){ | ||
"users": []func(c client.Collection){ | ||
func(c client.Collection) { | ||
err = c.Save(context.Background(), doc1) | ||
assert.Nil(t, err) | ||
}, | ||
func(c client.Collection) { | ||
err = c.Save(context.Background(), doc2) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
}, | ||
ExpectedUpdates: []testUtils.ExpectedUpdate{ | ||
{ | ||
DocKey: immutable.Some(docKey1), | ||
}, | ||
{ | ||
DocKey: immutable.Some(docKey2), | ||
}, | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
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,67 @@ | ||
// 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 simple | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
testUtils "github.com/sourcenetwork/defradb/tests/integration/events" | ||
) | ||
|
||
func TestEventsSimpleWithCreateWithTxnDiscarded(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
DatabaseCalls: []func(context.Context, client.DB){ | ||
func(ctx context.Context, d client.DB) { | ||
r := d.ExecQuery( | ||
ctx, | ||
`mutation { | ||
create_users(data: "{\"Name\": \"John\"}") { | ||
_key | ||
} | ||
}`, | ||
) | ||
for _, err := range r.GQL.Errors { | ||
assert.Nil(t, err) | ||
} | ||
}, | ||
func(ctx context.Context, d client.DB) { | ||
txn, err := d.NewTxn(ctx, false) | ||
assert.Nil(t, err) | ||
r := d.ExecTransactionalQuery( | ||
ctx, | ||
`mutation { | ||
create_users(data: "{\"Name\": \"Shahzad\"}") { | ||
_key | ||
} | ||
}`, | ||
txn, | ||
) | ||
for _, err := range r.GQL.Errors { | ||
assert.Nil(t, err) | ||
} | ||
txn.Discard(ctx) | ||
}, | ||
}, | ||
ExpectedUpdates: []testUtils.ExpectedUpdate{ | ||
{ | ||
DocKey: immutable.Some("bae-43deba43-f2bc-59f4-9056-fef661b22832"), | ||
}, | ||
// No event should be recieved for Shahzad, as the transaction was discarded. | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
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,60 @@ | ||
// 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 simple | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
testUtils "github.com/sourcenetwork/defradb/tests/integration/events" | ||
) | ||
|
||
// This test documents undesirable behaviour which should be corrected in | ||
// https://github.com/sourcenetwork/defradb/issues/867 | ||
func TestEventsSimpleWithDelete(t *testing.T) { | ||
doc1, err := client.NewDocFromJSON( | ||
[]byte( | ||
`{ | ||
"Name": "John" | ||
}`, | ||
), | ||
) | ||
assert.Nil(t, err) | ||
docKey1 := doc1.Key().String() | ||
|
||
test := testUtils.TestCase{ | ||
CollectionCalls: map[string][]func(client.Collection){ | ||
"users": []func(c client.Collection){ | ||
func(c client.Collection) { | ||
err = c.Save(context.Background(), doc1) | ||
assert.Nil(t, err) | ||
}, | ||
func(c client.Collection) { | ||
wasDeleted, err := c.Delete(context.Background(), doc1.Key()) | ||
assert.Nil(t, err) | ||
assert.True(t, wasDeleted) | ||
}, | ||
}, | ||
}, | ||
ExpectedUpdates: []testUtils.ExpectedUpdate{ | ||
{ | ||
DocKey: immutable.Some(docKey1), | ||
}, | ||
// No update to reflect the delete | ||
}, | ||
} | ||
|
||
executeTestCase(t, test) | ||
} |
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,80 @@ | ||
// 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 simple | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/sourcenetwork/immutable" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
testUtils "github.com/sourcenetwork/defradb/tests/integration/events" | ||
) | ||
|
||
func TestEventsSimpleWithUpdate(t *testing.T) { | ||
doc1, err := client.NewDocFromJSON( | ||
[]byte( | ||
`{ | ||
"Name": "John" | ||
}`, | ||
), | ||
) | ||
assert.Nil(t, err) | ||
docKey1 := doc1.Key().String() | ||
|
||
doc2, err := client.NewDocFromJSON( | ||
[]byte( | ||
`{ | ||
"Name": "Shahzad" | ||
}`, | ||
), | ||
) | ||
assert.Nil(t, err) | ||
docKey2 := doc2.Key().String() | ||
|
||
test := testUtils.TestCase{ | ||
CollectionCalls: map[string][]func(client.Collection){ | ||
"users": []func(c client.Collection){ | ||
func(c client.Collection) { | ||
err = c.Save(context.Background(), doc1) | ||
assert.Nil(t, err) | ||
}, | ||
func(c client.Collection) { | ||
err = c.Save(context.Background(), doc2) | ||
assert.Nil(t, err) | ||
}, | ||
func(c client.Collection) { | ||
// Update John | ||
doc1.Set("Name", "Johnnnnn") | ||
err = c.Save(context.Background(), doc1) | ||
assert.Nil(t, err) | ||
}, | ||
}, | ||
}, | ||
ExpectedUpdates: []testUtils.ExpectedUpdate{ | ||
{ | ||
DocKey: immutable.Some(docKey1), | ||
Cid: immutable.Some("bafybeihm4gewwhzsyqs7tuazdsbusp6pm3oinhnj2ae6funcwshwpxuxri"), | ||
fredcarle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
DocKey: immutable.Some(docKey2), | ||
}, | ||
{ | ||
DocKey: immutable.Some(docKey1), | ||
Cid: immutable.Some("bafybeicxo5sqjzi2mjputtbzwnkliickvowwfigyzziibtwlj7xe3ca7ly"), | ||
}, | ||
}, | ||
} | ||
|
||
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.
The linked ticket has been commented on with a reference to this test