This will show how to use the Gitlab CI for running puppet module tests.
First make sure to add test coverage to your rspec tests.
In spec/spec_helper.rb
add:
RSpec.configure do |c|
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end
Then add a .gitlab-ci.yml
configuration to your module project.
The following example will add jobs for lint, validate(syntax) and rspec(unit) tests:
image: "ruby:2.5"
cache:
paths:
- vendor/ruby
- spec/fixtures
before_script:
- gem install bundler --no-ri --no-rdoc
- bundle install -j $(nproc) --path vendor
test-validate:
stage: test
tags:
- docker-runner
script:
- bundle exec rake validate
test-lint:
stage: test
tags:
- docker-runner
script:
- bundle exec rake lint
test-rspec:
stage: test
tags:
- docker-runner
script:
- bundle exec rake spec
coverage: '/Resource coverage: \d+\.\d+/'
Gitlab provides a job status and a coverage status badge.
You can find the code to include in your README.md
at:
Project Settings -> CI / CD -> General pipelines settings