CFINSPEC-80: Skeleton of resource, unit test and doc

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-03-30 16:11:12 +05:30
parent 4ed3d4bcc7
commit f1f0ecb631
3 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,77 @@
+++
title = "mail_alias resource"
draft = false
gh_repo = "inspec"
platform = "unix"
[menu]
[menu.inspec]
title = "mail_alias"
identifier = "inspec/resources/os/mail_alias.md mail_alias resource"
parent = "inspec/resources/os"
+++
Use the `mail_alias` Chef InSpec audit resource to test the ...
## Availability
### Installation
This resource is distributed along with Chef InSpec itself. You can use it automatically.
## Syntax
A `mail_alias` Chef InSpec audit resource ...
describe mail_alias do
its('shoe_size') { should cmp 42 }
it { should be_purple }
it { should have_bells }
end
where
- `'shoe_size'` is some property of this resource
- `42` is the value to test for shoe size
- `be_purple` is a matcher of this resource
- `have_bells` is a matcher of this resource
## Properties
- Properties of the resources: `shoe_size`
### shoe_size
The shoe_size property tests ....
## Matchers
For a full list of available matchers, please visit our [matchers page](https://docs.chef.io/inspec/matchers/).
The specific matchers of this resource are: `be_purple`, `have_bells`
### be_purple
The `be_purple` matcher tests the ...:
it { should be_purple }
## Examples
The following examples show how to use this Chef InSpec audit resource.
### Example 1
`shoe_size` returns ...
describe mail_alias do
its("shoe_size") { should eq 42 }
end
### Example 2
`be_purple` checks for ...
describe mail_alias do
it { should be_purple }
end

View file

@ -0,0 +1,47 @@
require "inspec/resources/command"
module Inspec::Resources
class Mailalias < Inspec.resource(1)
# resource internal name.
name "mail_alias"
# Restrict to only run on the below platforms (if none were given,
# all OS's and cloud API's supported)
supports platform: "unix"
desc "Use the mail_alias InSpec audit resource to test mail_alias parameters"
example <<~EXAMPLE
describe mail_alias('toor') do
it { should be_aliased_to 'root' }
end
EXAMPLE
def initialize(alias_key)
skip_resource "The `mail_alias` resource is not yet available on your OS." unless inspec.os.unix?
@alias_key = alias_key
end
# resource_id is used in reporting engines to uniquely identify the individual resource.
def resource_id
"#{@alias_key}"
end
# Define how you want your resource to appear in test reports. Commonly, this is just the resource name and the resource ID.
def to_s
"mail_alias #{resource_id}"
end
def is_aliased_to?(alias_value)
# positive or negative expectations specific to this resource instance
true
end
private
# Methods to help the resource's public methods
def helper_method
# Add anything you need here
end
end
end

View file

@ -0,0 +1,20 @@
require "inspec/globals"
require "#{Inspec.src_root}/test/helper"
require_relative "../../../lib/inspec/resources/mail_alias"
describe Inspec::Resources::Mailalias do
it "check mail alias on ubuntu" do
resource = MockLoader.new(:ubuntu).load_resource("mail_alias", "daemon")
_(resource.is_aliased_to?("root")).must_equal true
end
it "check mail alias on macos" do
resource = MockLoader.new(:macos10_10).load_resource("mail_alias", "daemon")
_(resource.is_aliased_to?("root")).must_equal true
end
it "check mail alias on freebsd" do
resource = MockLoader.new(:freebsd11).load_resource("mail_alias", "daemon")
_(resource.is_aliased_to?("root")).must_equal true
end
end