Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions spec/reports/AllJsonRecipes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::AllJsonRecipes do
let(:mock_kb) { MockKnowledgeBase.new(:recipejsons => recipejsons) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no JSON recipes' do
let(:recipejsons) { {} }

it 'returns empty array' do
expect(report.to_a).to eq([])
end

it 'output returns empty array' do
expect(report.output).to eq([])
end
end

describe 'with JSON recipes' do
let(:recipejsons) do
{
'fb_helpers::default' => { 'path' => '/path/to/default.json' },
'fb_init::default' => { 'path' => '/path/to/init.json' },
'fb_aaa::setup' => { 'path' => '/path/to/aaa.json' },
}
end

it 'returns sorted recipe names' do
expect(report.to_a).to eq([
'fb_aaa::setup',
'fb_helpers::default',
'fb_init::default',
])
end

it 'output returns sorted recipe names' do
expect(report.output).to eq([
'fb_aaa::setup',
'fb_helpers::default',
'fb_init::default',
])
end
end
end
70 changes: 70 additions & 0 deletions spec/reports/AllReferencedRecipes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::AllReferencedRecipes do
let(:mock_kb) { MockKnowledgeBase.new(:roles => roles, :recipes => recipes) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no roles or recipes' do
let(:roles) { {} }
let(:recipes) { {} }

it 'returns empty array' do
expect(report.to_a).to eq([])
end

it 'output returns empty array' do
expect(report.output).to eq([])
end
end

describe 'with roles and recipes referencing recipes' do
let(:roles) do
{
'base_role' => {
'RoleRunListRecipes' => ['fb_init::default', 'fb_helpers::default'],
},
}
end
let(:recipes) do
{
'fb_init::default' => {
'IncludeRecipeLiterals' => ['fb_sysctl::default', 'fb_helpers::default'],
},
'fb_helpers::default' => {
'IncludeRecipeLiterals' => [],
},
}
end

it 'returns sorted unique recipes from roles and recipes' do
expect(report.to_a).to eq([
'fb_helpers::default',
'fb_init::default',
'fb_sysctl::default',
])
end

it 'output returns sorted unique recipes' do
expect(report.output).to eq([
'fb_helpers::default',
'fb_init::default',
'fb_sysctl::default',
])
end
end
end
49 changes: 49 additions & 0 deletions spec/reports/AllRoleDescriptions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::AllRoleDescriptions do
let(:mock_kb) { MockKnowledgeBase.new(:roles => roles) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no roles' do
let(:roles) { {} }

it 'returns empty string' do
expect(report.to_plain).to eq('')
end
end

describe 'with roles having descriptions' do
let(:roles) do
{
'web_role' => {
'RoleDescription' => 'Web server configuration',
},
'base_role' => {
'RoleDescription' => 'Base system settings',
},
}
end

it 'returns sorted roles with descriptions' do
output = report.to_plain
expect(output).to include('role: base_role desc: Base system settings')
expect(output).to include('role: web_role desc: Web server configuration')
expect(output.index('base_role')).to be < output.index('web_role')
end
end
end
59 changes: 59 additions & 0 deletions spec/reports/CookbookDependencyDot_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::CookbookDependencyDot do
let(:mock_kb) { MockKnowledgeBase.new(:metadatarbs => metadatarbs) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no metadata.rb files' do
let(:metadatarbs) { {} }

it 'returns empty digraph' do
expect(report.to_s).to eq("digraph deps {\n\n}")
end

it 'output returns empty digraph' do
expect(report.output).to eq("digraph deps {\n\n}")
end
end

describe 'with metadata.rb files having dependencies' do
let(:metadatarbs) do
{
'fb_helpers::metadata.rb' => {
'ExplicitMetadataDepends' => ['fb_init'],
},
'fb_apache::metadata.rb' => {
'ExplicitMetadataDepends' => ['fb_helpers', 'fb_sysctl'],
},
}
end

it 'returns DOT format with dependencies' do
output = report.to_s
expect(output).to start_with('digraph deps {')
expect(output).to end_with('}')
expect(output).to include('fb_helpers->fb_init')
expect(output).to include('fb_apache->fb_helpers')
expect(output).to include('fb_apache->fb_sysctl')
end

it 'output returns DOT format' do
expect(report.output).to eq(report.to_s)
end
end
end
67 changes: 67 additions & 0 deletions spec/reports/CookbookNameAndMaintainerEmail_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::CookbookNameAndMaintainerEmail do
let(:mock_kb) { MockKnowledgeBase.new(:metadatarbs => metadatarbs) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no metadata.rb files' do
let(:metadatarbs) { {} }

it 'returns empty array' do
expect(report.to_a).to eq([])
end

it 'output returns empty array' do
expect(report.output).to eq([])
end
end

describe 'with metadata.rb files having name and maintainer_email' do
let(:metadatarbs) do
{
'fb_helpers::metadata.rb' => {
'MetadatarbAttributeLiterals' => {
:name => 'fb_helpers',
:maintainer_email => 'team@example.com',
},
},
'fb_apache::metadata.rb' => {
'MetadatarbAttributeLiterals' => {
:name => 'fb_apache',
:maintainer_email => 'webteam@example.com',
},
},
}
end

it 'returns sorted CSV format' do
result = report.to_a
expect(result).to eq([
'fb_apache,webteam@example.com',
'fb_helpers,team@example.com',
])
end

it 'output returns sorted CSV format' do
expect(report.output).to eq([
'fb_apache,webteam@example.com',
'fb_helpers,team@example.com',
])
end
end
end
66 changes: 66 additions & 0 deletions spec/reports/DynamicRecipeInclusion_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2026-present, Meta Platforms, Inc. and affiliates
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './spec_helper'

describe Bookworm::Reports::DynamicRecipeInclusion do
let(:mock_kb) { MockKnowledgeBase.new(:recipes => recipes) }
let(:report) { described_class.allocate.tap { |r| r.instance_variable_set(:@kb, mock_kb) } }

describe 'with no recipes' do
let(:recipes) { {} }

it 'returns empty array' do
expect(report.to_a).to eq([])
end

it 'output returns empty array' do
expect(report.output).to eq([])
end
end

describe 'with recipes having dynamic inclusion' do
let(:recipes) do
{
'fb_helpers::default' => {
'IncludeRecipeDynamic' => false,
},
'fb_init::default' => {
'IncludeRecipeDynamic' => true,
},
'fb_apache::setup' => {
'IncludeRecipeDynamic' => true,
},
'fb_nginx::default' => {
'IncludeRecipeDynamic' => nil,
},
}
end

it 'returns sorted recipes with dynamic inclusion' do
expect(report.to_a).to eq([
'fb_apache::setup',
'fb_init::default',
])
end

it 'output returns sorted recipes with dynamic inclusion' do
expect(report.output).to eq([
'fb_apache::setup',
'fb_init::default',
])
end
end
end
Loading
Loading