Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert tests to InSpec tests #641

Merged
merged 2 commits into from
Jan 7, 2025
Merged
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
13 changes: 9 additions & 4 deletions .github/actions/test-kitchen/action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: 'Test Kitchen Action'
description: 'Runs Test Kitchen tests with the specified suite and OS'
name: "Test Kitchen Action"
description: "Runs Test Kitchen tests with the specified suite and OS"
inputs:
suite:
description: 'Test suite to run'
description: "Test suite to run"
required: true
os:
description: 'OS to test on'
description: "OS to test on"
required: true
chef_version:
description: "Chef version to use"
required: false
default: "current"

runs:
using: "composite"
Expand All @@ -18,6 +22,7 @@ runs:
env:
CHEF_LICENSE: accept-no-persist
KITCHEN_LOCAL_YAML: kitchen.dokken.yml
CHEF_VERSION: ${{ inputs.chef_version }}
with:
suite: ${{ inputs.suite }}
os: ${{ inputs.os }}
20 changes: 3 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,7 @@ jobs:
with:
suite: ${{ matrix.suite }}
os: ${{ matrix.os }}

# TODO: This is currently broken
# integration-repo-overrides:
# needs: lint-unit
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# os: ["ubuntu-2204", "ubuntu-2404"]
# suite: ["repo-overrides"]
# steps:
# - name: Check out code
# uses: actions/checkout@v4
# - uses: ./.github/actions/test-kitchen
# with:
# suite: ${{ matrix.suite }}
# os: ${{ matrix.os }}
chef_version: ${{ vars.CHEF_VERSION }}

integration-epel:
needs: lint-unit
Expand All @@ -89,6 +73,7 @@ jobs:
with:
suite: ${{ matrix.suite }}
os: ${{ matrix.os }}
chef_version: ${{ vars.CHEF_VERSION }}

integration-nginx-full:
needs: lint-unit
Expand All @@ -105,6 +90,7 @@ jobs:
with:
suite: ${{ matrix.suite }}
os: ${{ matrix.os }}
chef_version: ${{ vars.CHEF_VERSION }}

final:
runs-on: ubuntu-latest
Expand Down
1,942 changes: 1,509 additions & 433 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kitchen.global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ platforms:
- name: almalinux-8
- name: almalinux-9
- name: amazonlinux-2023
- name: centos-stream-10
- name: centos-stream-9
- name: debian-11
- name: debian-12
- name: fedora-latest
Expand Down
21 changes: 0 additions & 21 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,55 +32,34 @@ suites:
- name: distro
run_list:
- recipe[test::distro]
- recipe[test::test_site]
verifier:
inspec_tests:
- test/integration/default
- test/integration/default_install
- name: distro-nginx-full
run_list:
- recipe[test::distro_nginx-full]
- recipe[test::test_site]
includes:
- ubuntu-22.04
- ubuntu-24.04
verifier:
inspec_tests:
- test/integration/default
- test/integration/default_install
- name: repo
run_list:
- recipe[test::repo]
- recipe[test::test_site]
verifier:
inspec_tests:
- test/integration/default
- test/integration/repo
- test/integration/repo_install
- name: repo_overrides
run_list:
- recipe[test::repo_overrides]
- recipe[test::test_site]
verifier:
inspec_tests:
- test/integration/default
- test/integration/repo_overrides
- test/integration/repo_install
- name: epel
run_list:
- recipe[test::epel]
- recipe[test::test_site]
includes:
- almalinux-8
- almalinux-9
- centos-stream-9
- centos-stream-10
- rockylinux-8
- rockylinux-9
verifier:
inspec_tests:
- test/integration/default
- test/integration/epel
- name: invalid-conf
run_list:
- recipe[test::invalid-conf]
4 changes: 3 additions & 1 deletion test/cookbooks/test/recipes/distro.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apt_update 'update' if platform_family?('debian')
apt_update 'update'

nginx_install 'distro'

include_recipe 'test::test_site'
2 changes: 2 additions & 0 deletions test/cookbooks/test/recipes/distro_nginx-full.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
nginx_install 'distro' do
packages 'nginx-full'
end

include_recipe 'test::test_site'
2 changes: 2 additions & 0 deletions test/cookbooks/test/recipes/epel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
nginx_install 'nginx' do
source 'epel'
end

include_recipe 'test::test_site'
4 changes: 3 additions & 1 deletion test/cookbooks/test/recipes/repo.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apt_update 'update' if platform_family?('debian')
apt_update 'update'

nginx_install 'nginx' do
source 'repo'
end

include_recipe 'test::test_site'
16 changes: 0 additions & 16 deletions test/cookbooks/test/recipes/repo_overrides.rb

This file was deleted.

87 changes: 0 additions & 87 deletions test/integration/default/config_test.rb

This file was deleted.

104 changes: 104 additions & 0 deletions test/integration/default/controls/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
control 'nginx-config-01' do
impact 1.0
title 'Nginx Configuration Directories'
desc 'Ensure Nginx configuration directories exist with proper permissions'

describe directory('/etc/nginx') do
it { should exist }
end

%w(conf.d conf.http.d).each do |dir|
describe directory("/etc/nginx/#{dir}") do
it { should exist }
it { should be_directory }
its('mode') { should cmp '0755' }
end
end

describe directory('/var/log/nginx') do
it { should exist }
it { should be_directory }
its('mode') { should cmp '0755' }
end
end

control 'nginx-config-02' do
impact 1.0
title 'Nginx Default Configuration Files'
desc 'Ensure default configuration files are not present'

%w(default.conf example_ssl.conf).each do |config|
describe file("/etc/nginx/conf.d/#{config}") do
it { should_not exist }
end
end
end

control 'nginx-config-03' do
impact 1.0
title 'Nginx Main Configuration'
desc 'Verify the main nginx.conf configuration'

process_owner = case os.family
when 'debian'
'www-data'
else
'nginx'
end

describe file('/etc/nginx/nginx.conf') do
it { should exist }
it { should be_file }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('content') { should match(/user\s+#{process_owner};/) }
its('content') { should include 'worker_processes auto;' }
its('content') { should include 'pid /run/nginx.pid;' }
its('content') { should include 'worker_connections 1024;' }
its('content') { should include 'sendfile on;' }
its('content') { should include 'tcp_nopush on;' }
its('content') { should include 'tcp_nodelay on;' }
its('content') { should include 'keepalive_timeout 65;' }
its('content') { should include 'types_hash_max_size 2048;' }
end
end

control 'nginx-config-04' do
impact 1.0
title 'Nginx Site Configurations'
desc 'Verify various site configuration files'

describe file('/etc/nginx/conf.http.d/default-site.conf') do
it { should exist }
it { should be_file }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('content') { should include 'listen 80;' }
its('content') { should include 'access_log /var/log/nginx/localhost.access.log;' }
case os.family
when 'redhat'
its('content') { should include 'root /usr/share/nginx/html;' }
when 'debian'
its('content') { should include 'root /var/www/html;' }
end
end

describe file('/etc/nginx/conf.http.d/test_site.conf') do
it { should exist }
it { should be_file }
its('mode') { should cmp '0644' }
end

describe file('/etc/nginx/conf.http.d/test_site_disabled.conf.disabled') do
it { should exist }
it { should be_file }
end

describe file('/etc/nginx/conf.http.d/foo.conf') do
it { should exist }
it { should be_file }
its('content') { should include '## OVERRIDE FROM TEST COOKBOOK' }
its('content') { should include 'upstream bar {' }
its('content') { should include ' server localhost:1234;' }
end
end
11 changes: 11 additions & 0 deletions test/integration/default/controls/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
control 'nginx-service-01' do
impact 1.0
title 'Nginx Service'
desc 'Verify that Nginx service is installed, enabled and running'

describe service('nginx') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
7 changes: 7 additions & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: default
title: Nginx Suite
summary: Nginx integration tests
supports:
- os-family: linux
- os-family: bsd
5 changes: 0 additions & 5 deletions test/integration/default/service_test.rb

This file was deleted.

Loading
Loading