adds test for core resource iheritance in custom resource

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
Vasu1105 2022-02-01 12:51:44 +05:30
parent d8798eca83
commit e26ef71a6b
7 changed files with 79 additions and 1 deletions

10
test/fixtures/files/node.json vendored Normal file
View file

@ -0,0 +1,10 @@
{
"name" : "hello",
"meta" : {
"creator" : "John Doe"
},
"array": [
"zero",
"one"
]
}

View file

@ -0,0 +1,3 @@
# Example InSpec Profile
This example shows the implementation of an InSpec profile.

View file

@ -0,0 +1,23 @@
# copyright: 2018, The Authors
# title "sample section"
# # you can also use plain tests
# describe file("/tmp") do
# it { should be_directory }
# end
# # you add controls here
# control "tmp-1.0" do # A unique ID for this control
# impact 0.7 # The criticality, if this control fails.
# title "Create /tmp directory" # A human-readable title
# desc "An optional description..."
# describe file("/tmp") do # The actual test
# it { should be_directory }
# end
# end
describe node do
its("name") { should eq "hello" }
its(['meta','creator']) { should eq 'John Doe' }
end

View file

@ -0,0 +1,10 @@
name: custom-resource-inheritance
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
supports:
platform: os

View file

@ -0,0 +1,13 @@
require "inspec/resources/json"
class NodeAttributes < JsonConfig
name 'node'
def initialize
super('./test/fixtures/files/node.json')
end
def to_s
"Node Json"
end
end

View file

@ -1,4 +1,5 @@
require "functional/helper"
require "helpers/mock_loader"
describe "inspec exec" do
parallelize_me!
@ -163,7 +164,6 @@ Test Summary: 0 successful, 0 failures, 0 skipped
it "executes a specs-only profile" do
inspec("exec " + File.join(profile_path, "spec_only") + " --no-create-lockfile")
_(stdout).must_include "Target: local://"
_(stdout).must_include "working"
_(stdout).must_include "✔ is expected to eq \"working\""
@ -521,6 +521,25 @@ Test Summary: 0 successful, 0 failures, 0 skipped
end
end
describe "with a profile that inherits core resource into custom reosuce" do
let(:out) { inspec("exec " + File.join(profile_path, "custom-resource-inheritance") + " --no-create-lockfile") }
it "executes the custom resoruc without error" do
_(stdout).must_equal "
Profile: InSpec Profile (custom-resource-inheritance)
Version: 0.1.0
Target: local://
Node Json
name is expected to eq \"hello\"
[\"meta\", \"creator\"] is expected to eq \"John Doe\"
Test Summary: 2 successful, 0 failures, 0 skipped
"
_(stderr).must_equal ""
assert_exit_code 0, out
end
end
describe "given a profile with controls and anonymous describe blocks" do
let(:out) { inspec("exec " + example_control + " --no-create-lockfile") }