mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
CFINSPEC-80: Skeleton of resource, unit test and doc
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
4ed3d4bcc7
commit
f1f0ecb631
3 changed files with 144 additions and 0 deletions
77
docs-chef-io/content/inspec/resources/mail_alias.md
Normal file
77
docs-chef-io/content/inspec/resources/mail_alias.md
Normal 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
|
||||
|
47
lib/inspec/resources/mail_alias.rb
Normal file
47
lib/inspec/resources/mail_alias.rb
Normal 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
|
20
test/unit/resources/mail_alias_test.rb
Normal file
20
test/unit/resources/mail_alias_test.rb
Normal 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
|
Loading…
Reference in a new issue