forked from sourcenetwork/defradb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b21e0a9
commit e9f9d72
Showing
9 changed files
with
275 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
142 changes: 142 additions & 0 deletions
142
tests/integration/schema/with_update_set_default_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,142 @@ | ||
// Copyright 2023 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 schema | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestSchema_WithUpdateAndSetDefaultVersionToEmptyString_Errors(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test schema update, set default version to empty string", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, | ||
}, | ||
testUtils.SchemaPatch{ | ||
Patch: ` | ||
[ | ||
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "email", "Kind": 11} } | ||
] | ||
`, | ||
}, | ||
testUtils.SetDefaultSchemaVersion{ | ||
SchemaVersionID: "", | ||
ExpectedError: "schema version ID can't be empty", | ||
}, | ||
}, | ||
} | ||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestSchema_WithUpdateAndSetDefaultVersionToUnknownVersion_Errors(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test schema update, set default version to invalid string", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, | ||
}, | ||
testUtils.SchemaPatch{ | ||
Patch: ` | ||
[ | ||
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "email", "Kind": 11} } | ||
] | ||
`, | ||
}, | ||
testUtils.SetDefaultSchemaVersion{ | ||
SchemaVersionID: "does not exist", | ||
ExpectedError: "datastore: key not found", | ||
}, | ||
}, | ||
} | ||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestSchema_WithUpdateAndSetDefaultVersionToOriginal_NewFieldIsNotQueriable(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test schema update, set default version to original schema version", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, | ||
}, | ||
testUtils.SchemaPatch{ | ||
Patch: ` | ||
[ | ||
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "email", "Kind": 11} } | ||
] | ||
`, | ||
}, | ||
testUtils.SetDefaultSchemaVersion{ | ||
SchemaVersionID: "bafkreihn4qameldz3j7rfundmd4ldhxnaircuulk6h2vcwnpcgxl4oqffq", | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users { | ||
name | ||
} | ||
}`, | ||
// As the email field did not exist at this schema version, it will return a gql error | ||
ExpectedError: `Cannot query field "email" on type "Users".`, | ||
}, | ||
}, | ||
} | ||
testUtils.ExecuteTestCase(t, test) | ||
} | ||
|
||
func TestSchema_WithUpdateAndSetDefaultVersionToNew_AllowsQueryingOfNewField(t *testing.T) { | ||
test := testUtils.TestCase{ | ||
Description: "Test schema update, set default version to new schema version", | ||
Actions: []any{ | ||
testUtils.SchemaUpdate{ | ||
Schema: ` | ||
type Users { | ||
name: String | ||
} | ||
`, | ||
}, | ||
testUtils.SchemaPatch{ | ||
Patch: ` | ||
[ | ||
{ "op": "add", "path": "/Users/Schema/Fields/-", "value": {"Name": "email", "Kind": 11} } | ||
] | ||
`, | ||
}, | ||
testUtils.SetDefaultSchemaVersion{ | ||
SchemaVersionID: "bafkreidejaxpsevyijnr4nah4e2l263emwhdaj57fwwv34eu5rea4ff54e", | ||
}, | ||
testUtils.Request{ | ||
Request: `query { | ||
Users { | ||
name | ||
} | ||
}`, | ||
Results: []map[string]any{}, | ||
}, | ||
}, | ||
} | ||
testUtils.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
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