Skip to content

[Feature Request] Add ability to Unit Test Templates  #643

@shadycuz

Description

@shadycuz

Now that #622 is merged it's a lot easier to work with Taskcat from inside python. During the process of developing the feature for functional testing from inside python I kept having problems with credentials. Setting them on the CLI and then refreshing them. It was a nightmare. It had me thinking about this whole testing thing and really the types of tests that I was writing were really only testing the Cloudformation service. Things like is X resource created or is "String" in Resource Name. None of these things need to be deployed to AWS be tested. What I was really doing was writing my unit tests as functional tests to make them work.

So I started thinking about what would it take to test a cloudformation template locally in order to do these unit tests.

  1. Load all the template parameters either by taking user input or using the defaults provided for that parameter.
  2. Resolve the conditionals
  3. Resolve all intrinsic functions in the resources/outputs section.

The only somewhat tricky part here I found is when dealing with a nested intrinsic function you need to resolve from the deepest function and work your way out. It took 3 or 4 hours but I was able to build a rough POC. After a few days I had a nice working MVP. You can see how it works in the README under 'Usage'. The logic is quite simple and is all here. It's mostly ready to go except these few shortcomings:

  • Implement all AWS intrinsic functions.
    • Only !Ref, !Sub, !Equals and !If currently supported.
  • Add full functionality to pseudo variables.
    • Variables like Partition, URLSuffix should change if the region changes.
    • Variables like StackName and StackId should have a better default than ""
  • Handle References to resources that shouldn't exist.
    • It's currently possible that a !Ref to a Resource stays in the final template even if that resource is later removed because of a conditional.

If the Taskcat maintainers would like this functionality I can begin porting it into taskcat.

@andrew-glenn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions