-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Registers resolver instance * Adds ResolveRequiredService convenience function to resolve and safe-cast objects * Adds test to cover new functionality
- Loading branch information
1 parent
0a873f0
commit b780037
Showing
7 changed files
with
65 additions
and
3 deletions.
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
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
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,42 @@ | ||
package pkg | ||
|
||
import ( | ||
"context" | ||
"github.com/matzefriedrich/parsley/internal" | ||
"github.com/matzefriedrich/parsley/pkg/types" | ||
"github.com/stretchr/testify/assert" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_Resolver_ResolveRequiredService_factory_function_receives_current_resolver(t *testing.T) { | ||
|
||
// Arrange | ||
sut := NewServiceRegistry() | ||
_ = RegisterSingleton(sut, NewFactory) | ||
|
||
r := sut.BuildResolver() | ||
ctx := internal.NewScopedContext(context.Background()) | ||
|
||
// Act | ||
serviceFactory, _ := ResolveRequiredService[FactoryService](r, ctx) | ||
f := serviceFactory.(*factory) | ||
actual := f.resolver | ||
|
||
// Assert | ||
assert.NotNil(t, serviceFactory) | ||
|
||
assert.NotNil(t, actual) | ||
assert.Equal(t, reflect.ValueOf(r).Pointer(), reflect.ValueOf(actual).Pointer()) | ||
} | ||
|
||
type factory struct { | ||
resolver types.Resolver | ||
} | ||
|
||
type FactoryService interface { | ||
} | ||
|
||
func NewFactory(resolver types.Resolver) FactoryService { | ||
return &factory{resolver: resolver} | ||
} |
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