-
Notifications
You must be signed in to change notification settings - Fork 2
fix: align thread-safety docs and add CI test coverage #37
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c254831
fix: align thread-safety docs and add CI test coverage
kooksee 4094406
test: add coverage for context and global helpers
kooksee 20703e0
docs: streamline README structure and diagnostics guide
kooksee 08953d2
test: expand wrapper coverage and add README link checks
kooksee a86b91c
docs: add dixhttp auth guidance and PR template
kooksee 354d17d
chore: remove README link checker tooling
kooksee 67bd282
docs(example): simplify samples for easier onboarding
kooksee 8273aec
test: isolate global InjectT test and align API docs
kooksee 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,49 @@ | ||
| package dix | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestVersion(t *testing.T) { | ||
| if Version() == "" { | ||
| t.Fatal("Version() returned empty string") | ||
| } | ||
| } | ||
|
|
||
| func TestTryProvide(t *testing.T) { | ||
| di := New() | ||
|
|
||
| type svc struct{ Name string } | ||
|
|
||
| if err := TryProvide(di, func() *svc { return &svc{Name: "ok"} }); err != nil { | ||
| t.Fatalf("TryProvide: %v", err) | ||
| } | ||
|
|
||
| if err := TryProvide(di, nil); err == nil { | ||
| t.Fatal("TryProvide(nil) should return error") | ||
| } | ||
| } | ||
|
|
||
| func TestTryInject(t *testing.T) { | ||
| di := New() | ||
|
|
||
| type dep struct{ V int } | ||
|
|
||
| if err := TryProvide(di, func() *dep { return &dep{V: 1} }); err != nil { | ||
| t.Fatalf("TryProvide: %v", err) | ||
| } | ||
|
|
||
| called := false | ||
| if err := TryInject(di, func(d *dep) { called = d.V == 1 }); err != nil { | ||
| t.Fatalf("TryInject: %v", err) | ||
| } | ||
| if !called { | ||
| t.Fatal("TryInject callback was not invoked correctly") | ||
| } | ||
|
|
||
| if err := TryInject(di, func(*missingType) {}); err == nil { | ||
| t.Fatal("TryInject with missing dependency should return error") | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| type missingType struct{} | ||
This file contains hidden or 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
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.
To complete the newly exposed
Try*API suite and match the existingInjectTandInjectTContexthelpers, consider addingTryInjectTandTryInjectTContextfunctions.Currently, there is no safe way to inject into a struct of type
Tand return it along with an error without writing verbose boilerplate. Adding these helpers provides a clean, safe, and consistent way to perform struct-targeted dependency injection.