Skip to content

Commit

Permalink
test(inspec): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
genaumann committed Dec 16, 2023
1 parent 296ba21 commit 1aadcf4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/integration/default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Inspec Profile: `default`

Test git formulas

## Test Cases

- [system git configuration](./controls/system_conf.rb)
- [user git configuration](./controls/user_conf.rb)
- [repo cloned and updated by git](./controls/repo.rb)
20 changes: 20 additions & 0 deletions test/integration/default/controls/repo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

control "Repo #{os.name}" do
title 'Test git repos'

dirs = ["/home/vagrant/container", "/home/vagrant/cib"]
dirs.each do | dir |
describe directory(dir) do
it { should exist }
end
describe directory(dir + '/.git') do
it { should exist }
end
end

describe file('/home/vagrant/cib/VERSION') do
its('content') { should eq "1.0.4\n" }
end

end
14 changes: 14 additions & 0 deletions test/integration/default/controls/system_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

control "Global conf #{os.name}" do
title 'Test global conf'

describe file('/etc/gitconfig') do
it { should be_file }
end

describe command('git config --get alias.st') do
its('exit_status') { should eq 0 }
its('stdout') { should eq "status\n" }
end
end
18 changes: 18 additions & 0 deletions test/integration/default/controls/user_conf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

control "User conf #{os.name}" do
title 'Test user conf'

describe command('git config --get user.email') do
its('exit_status') { should eq 0 }
its('stdout') { should eq "[email protected]\n" }
end
describe command('git config --get user.name') do
its('exit_status') { should eq 0 }
its('stdout') { should eq "Gino Naumann\n" }
end
describe command('git -C /home/vagrant/cib config --get user.name') do
its('exit_status') { should eq 0 }
its('stdout') { should eq "Rainer Zufall\n" }
end
end
10 changes: 10 additions & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: default
title: git formula
maintainer: Gino Naumann
version: 0.0.0
licence: Apache-2.0
summary: Verify that the git state manages git correctly
supports:
- platform-name: ubuntu
- platform-name: debian
15 changes: 15 additions & 0 deletions test/salt/pillar/repo.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
git:
repo:
container:
name: https://gitlab.com/genaumann/containerpub
target: /home/vagrant/container
cib:
name: https://gitlab.com/genaumann/cib
state: latest
rev: v1.0.4
user: vagrant
target: /home/vagrant/cib
php:
name: https://github.com/php/php-src
state: absent
9 changes: 9 additions & 0 deletions test/salt/pillar/system_config.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
git:
system_config:
alias:
st: status
fe: fetch
pu: push
init:
defaultbranch: main
17 changes: 17 additions & 0 deletions test/salt/pillar/user_config.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
git:
user_config:
- key: user.email
value: [email protected]
user: vagrant
- key: user.name
value: Gino Naumann
user: vagrant
- key: user.name
value: Rainer Zufall
repo: /home/vagrant/cib
user: vagrant
- key: 'remote\..+'
state: absent
repo: /home/vagrant/container
user: vagrant

0 comments on commit 1aadcf4

Please sign in to comment.