1.

Write and explain a simple InSpec test?

Answer»

InSpec is an in-built testing framework for testing and auditing infrastructure in Chef. A sample InSpec test to verify whether “Nginx” server is INSTALLED and running in a system could be written as follows:

```control 'Nginx-install-1.0' do      title 'Check if nginx is installed'      describe package 'nginx' do       it { should be_installed }      end    end      control 'Nginx should be running' do      describe service 'nginx' do    it { should be_running }      end    end```

Main components of InSpec tests are:

  • Control: A requirement is defined inside a control block
  • Title: Title defines the metadata of the control block describing the importance of the requirement.
  • Resource: Resources are the basic building blocks of infrastructure. A control block may have multiple resources. Resources could be anything like file, package, service, etc.
  • Describe: Tests for a particular resource is GROUPED into a describe block. A control block should have a minimum one describe block. A describe block is defined within a “do end” block
  • It or its: Each line starting with "it" or "its" is a test to access resource-specific MATCHER. “should be_installed” and “should be_running” are in-built METHODS in DSL to verify whether the package is installed and whether the service is running.


Discussion

No Comment Found