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(depinject): add preference feature #12202

Merged
Merged
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
84 changes: 84 additions & 0 deletions depinject/features/prefer.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Feature: interface type resolution

Background:
Given an interface Duck
And two implementations Mallard and Canvasback

Rule: interface types resolve to a concrete type implicitly if there is only one matching implementation
Example: only one implementation
Given "Mallard" is provided
When we try to resolve a "Duck" in global scope
Then "Mallard" is resolved in global scope

Example: two implementations
Given "Mallard" and "Canvasback" are provided
When we try to resolve a "Duck" in global scope
Then there is a "multiple implicit interface bindings" error

Rule: preferences must point to a real type
Example:
Given "Mallard" is provided
And there is a global preference for a "Marbled" "Duck"
When we try to resolve a "Duck" in global scope
Then there is a "no type for explicit binding" error

Rule: preferences supersede implicit type resolution
Example: global scope
Given "Canvasback" is provided
And there is a global preference for a "Mallard" "Duck"
When we try to resolve a "Duck" in global scope
Then there is a "can't resolve" error

Example: module scope
Given "Canvasback" is provided
And there is a preference for a "Mallard" "Duck" in module "A"
When module "A" wants a "Duck"
Then there is a "can't resolve" error

Rule: preferences in global scope apply to both global and module-scoped resolution (if there is no module-scoped preference)
Example: global resolution
Given "Mallard" and "Canvasback" are provided
And there is a global preference for a "Mallard" "Duck"
When we try to resolve a "Duck" in global scope
Then "Mallard" is resolved in global scope

Example: module-scoped resolution
Given "Mallard" and "Canvasback" are provided
And there is a global preference for a "Mallard" "Duck"
When module "A" wants a "Duck"
Then module "A" resolves a "Mallard"

Rule: module-scoped preferences only apply to module-scoped resolution
Example: a module-scoped binding doesn't work for global scope
Given "Mallard" and "Canvasback" are provided
And there is a preference for a "Canvasback" "Duck" in module "A"
When we try to resolve a "Duck" in global scope
Then there is a "multiple implicit interface bindings" error

Example: a module-scoped binding works for that module
Given "Mallard" and "Canvasback" are provided
And there is a preference for a "Canvasback" "Duck" in module "A"
When module "A" wants a "Duck"
Then module "A" resolves a "Canvasback"

Example: a module-scoped binding doesn't work for another module
Given "Mallard" and "Canvasback" are provided
And there is a preference for a "Canvasback" "Duck" in module "A"
When module "B" wants a "Duck"
Then there is a "multiple implicit interface bindings" error

# this case is called a "journey" scenario which tests a bunch of things together
# most tests should be short and to the point like the ones above but one or two long ones
# are good to test more things together &/or do integration tests
Example: two module-scoped preferences and a global preference
Given "Mallard" and "Canvasback" are provided
* there is a global preference for a "Mallard" "Duck"
* there is a preference for a "Canvasback" "Duck" in module "A"
* there is a preference for a "Mallard" "Duck" in module "B"
When module "A" wants a "Duck"
* module "B" wants a "Duck"
* module "C" wants a "Duck"
Then module "A" resolves a "Canvasback"
* module "B" resolves a "Mallard"
* module "C" resolves a "Mallard"
* "Mallard" is resolved in global scope