-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add better error when object config incomplete
When a service config is missing "value" or "config", it must be an object. If it is then also missing a "class", we get a cryptic error: "argument is not a module name". This is coming from Module::Runtime use_module. Now, if this situation happens, we throw an exception with a better error message.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Lib; | ||
use Test::Deep; | ||
use Test::Exception; | ||
use Beam::Wire; | ||
|
||
my $wire = Beam::Wire->new( | ||
config => { | ||
base_class => { | ||
class => 'My::ArgsTest', | ||
}, | ||
base_no_class => { }, | ||
}, | ||
); | ||
|
||
my $svc; | ||
|
||
lives_ok { $svc = $wire->create_service( 'testing', class => 'My::ArgsTest' ) } | ||
'create service with class only'; | ||
cmp_deeply $svc->got_args, [], 'no args given'; | ||
|
||
throws_ok { $svc = $wire->create_service( 'testing', path => '/foo/bar' ) } | ||
'Beam::Wire::Exception::InvalidConfig', | ||
'must have one of "class", "value", "config" in the merged config'; | ||
|
||
throws_ok { $svc = $wire->create_service( 'testing', extends => 'base_no_class' ) } | ||
'Beam::Wire::Exception::InvalidConfig', | ||
'merged config from extends must have one of "class", "value", "config" in the merged config'; | ||
|
||
throws_ok { $svc = $wire->create_service( 'testing', class => 'My::ArgsTest', value => '' ) } | ||
'Beam::Wire::Exception::InvalidConfig', | ||
'cannot use "value" with "class"'; | ||
throws_ok { $svc = $wire->create_service( 'testing', extends => 'base_class', value => '' ) } | ||
'Beam::Wire::Exception::InvalidConfig', | ||
'cannot use "value" with "extends"'; | ||
|
||
done_testing; |