-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically instantiate providers into the stack as required, including the ability to inject config from the service settings.
- Loading branch information
Showing
4 changed files
with
120 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from contextlib import suppress | ||
from unittest import skipUnless | ||
|
||
from cally.cdk import CallyResource, CallyStack | ||
|
||
from .. import CallyTfTestHarness | ||
|
||
skip_tests = False | ||
with suppress(ModuleNotFoundError): | ||
from cally.providers.random import pet # noqa: F401 | ||
|
||
skip_tests = True | ||
|
||
|
||
@skipUnless(skip_tests, "Random provider must be installed") | ||
class CallyProviderTests(CallyTfTestHarness): | ||
def test_provider_load(self): | ||
stack = CallyStack(service=self.empty_service) | ||
|
||
class Pet(CallyResource): | ||
provider = 'random' | ||
resource = 'pet' | ||
|
||
stack.add_resource(Pet('random-pet-name')) | ||
result = self.synth_stack(stack) | ||
testdata = self.load_json_file('cdk/provider_load.json') | ||
self.assertDictEqual(result.get('provider'), testdata.get('provider')) | ||
self.assertDictEqual(result.get('resource'), testdata.get('resource')) | ||
|
||
def test_provider_config(self): | ||
self.empty_service.providers.update(random={'alias': 'foo'}) | ||
stack = CallyStack(service=self.empty_service) | ||
|
||
class Pet(CallyResource): | ||
provider = 'random' | ||
resource = 'pet' | ||
|
||
stack.add_resource(Pet('random-pet-name')) | ||
result = self.synth_stack(stack) | ||
self.assertEqual( | ||
result.get('provider', {}).get('random', {})[0].get('alias', ''), 'foo' | ||
) |
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,20 @@ | ||
{ | ||
"provider": { | ||
"random": [ | ||
{} | ||
] | ||
}, | ||
"resource": { | ||
"random_pet": { | ||
"random-pet-name": { | ||
"//": { | ||
"metadata": { | ||
"path": "test/random-pet-name", | ||
"uniqueId": "random-pet-name" | ||
} | ||
}, | ||
"provider": "random" | ||
} | ||
} | ||
} | ||
} |