Usage
The class reads the yaml template saved, synthesizes the new template and compares between them.
You have to import the class TestSynth instead of unittest.TestCase package and your TestYourClass class has to extend it.
from tests.test_synth import TestSynth
from sample.yourclass import YourClass
class TestYourClass(TestSynth):
The method named __init__ has to call the class named TestSynth with the relative path of yaml template saved.
def __init__(self, *args, **kwargs):
TestSynth.__init__(self, 'tests/yourclass.yaml', *args, **kwargs)
There is the method named synth with the initialization of YourClass
def synth(self, app):
YourClass(app, id="name-of-your-stack")
If you have to manage more YourClass, you can use the method synthesizes
def your_synth(self, app):
YourClass(app, id="name-of-your-stack")
def test_your_synth(self):
self.synthesizes('your_synth')
It you have to manage more templates, you can use the method load_template
def your_synth(self, app):
YourClass(app, id=self.id)
def test_your_synth(self):
self.id = "name-of-your-synth"
self.load_template('tests/yoursynth.yaml')
self.synthesizes('your_synth')
Example
When you create your stack.py file, you can create your test_stack.py like the example in the tests folder of this repository. In that example, you can find
s3_stack.py, the example of your stack implementation
test_s3_stack.py, the example of your unittest class
s3.yaml, the template saved
When you run the unittest (see the Development Section),
before, you have to create a file empty named s3.yaml
the first time, you have to fill it with the first version
the times after, if the templates saved and new are different, so the unittest fails, you can evaluate if you have to save a new version or fix your change
You can find other examples in the repositories below: