6 Testing

 

This chapter covers

  • Identifying which type of tests to write for infrastructure systems
  • Writing tests to verify infrastructure configuration or modules
  • Understanding the cost of various types of tests

Recall from chapter 1 that infrastructure as code involves an entire process to push a change to a system. You update scripts or configurations with infrastructure changes, push them to a version control system, and apply the changes in an automated way. However, you can use every module and dependency pattern from chapters 3 and 4 and still have failed changes! How do you catch a failed change before you apply it to production?

You can solve this problem by implementing tests for IaC. Testing is a process that evaluates whether a system works as expected. This chapter reviews some considerations and concepts related to testing IaC to reduce the rate of change failure and build confidence in infrastructure changes.

Definition

Testing IaC is a process that evaluates whether infrastructure works as expected.

Imagine you configure a network switch with a new network segment. You can manually test existing networks by pinging each server on each network and verifying their connectivity. To test that you set up the new network correctly, you create a new server and check whether it responds when you connect to it. This manual test takes a few hours for two or three networks.

6.1 The infrastructure testing cycle

 
 
 

6.1.1 Static analysis

 
 

6.1.2 Dynamic analysis

 
 

6.1.3 Infrastructure testing environments

 
 

6.2 Unit tests

 

6.2.1 Testing infrastructure configuration

 
 
 

6.2.2 Testing domain-specific languages

 
 
 

6.2.3 When should you write unit tests?

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest