Merge pull request #2 from voxpupuli/cleanup

moving parameters into appropriate place, adding meaning unit test, f…
This commit is contained in:
Bram Vogelaar 2021-01-14 14:37:36 +01:00 committed by GitHub
commit 65e90f4653
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 118 additions and 12 deletions

8
.fixtures.yml Normal file
View file

@ -0,0 +1,8 @@
fixtures:
repositories:
apt: "https://github.com/puppetlabs/puppetlabs-apt.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
yum: "https://github.com/voxpupuli/puppet-yum.git"
yumrepo_core:
repo: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git"
puppet_version: ">= 6.0.0"

74
REFERENCE.md Normal file
View file

@ -0,0 +1,74 @@
# Reference
<!-- DO NOT EDIT: This document was generated by Puppet Strings -->
## Table of Contents
### Classes
* [`hashi_stack::repo`](#hashi_stackrepo): Set up the package repository for the HashiCorp Stack components
## Classes
### `hashi_stack::repo`
This class installs the hashicorp repository
#### Examples
#####
```puppet
include hashi_stack::repo
```
#####
```puppet
class { 'hashi_stack::repo': } -> package { 'packer': ensure => installed }
```
#### Parameters
The following parameters are available in the `hashi_stack::repo` class.
##### `priority`
Data type: `Optional[Integer]`
A numeric priority for the repo, passed to the package management system
Default value: ``undef``
##### `proxy`
Data type: `String`
The URL of a HTTP proxy to use for package downloads (YUM only)
Default value: `'absent'`
##### `key_id`
Data type: `String`
GPG key to authenticate Apt package signatures.
Default value: `'E8A032E094D8EB4EA189D270DA418C88A3219F7B'`
##### `key_source`
Data type: `Stdlib::HTTPSUrl`
The location of an existing GPG key file to copy.
Default value: `'https://apt.releases.hashicorp.com/gpg'`
##### `description`
Data type: `String`
Repository description
Default value: `'HashiCorp package repository.'`

5
example/init.pp Normal file
View file

@ -0,0 +1,5 @@
include hashi_stack::repo
package { 'packer':
ensure => installed,
require => Class['Hashi_stack::Repo'],
}

View file

@ -2,20 +2,28 @@
# #
# @summary Set up the package repository for the HashiCorp Stack components # @summary Set up the package repository for the HashiCorp Stack components
# #
# @example # @example Inclusion using defaults
# include hashi_stack::repo # include hashi_stack::repo
# #
# @example Include repo and install packer as package
# include hashi_stack::repo
# package { 'packer':
# ensure => installed,
# require => Class['Hashi_stack::Repo'],
# }
#
# @param priority A numeric priority for the repo, passed to the package management system # @param priority A numeric priority for the repo, passed to the package management system
# @param proxy The URL of a HTTP proxy to use for package downloads (YUM only) # @param proxy The URL of a HTTP proxy to use for package downloads (YUM only)
# @param base_repo_url The base url for the repo path # @param key_id GPG key to authenticate Apt package signatures.
# @param key_source The location of an existing GPG key file to copy.
# @param description Repository description
class hashi_stack::repo ( class hashi_stack::repo (
Optional[Integer] $priority = undef, Optional[Integer] $priority = undef,
String $proxy = 'absent', String $proxy = 'absent',
String $key_id = 'E8A032E094D8EB4EA189D270DA418C88A3219F7B',
Stdlib::HTTPSUrl $key_source = 'https://apt.releases.hashicorp.com/gpg',
String $description = 'HashiCorp package repository.',
) { ) {
$key_id='E8A032E094D8EB4EA189D270DA418C88A3219F7B'
$key_source='https://apt.releases.hashicorp.com/gpg'
$description='HashiCorp package repository.'
case $facts['os']['family'] { case $facts['os']['family'] {
'Debian': { 'Debian': {
include apt include apt
@ -25,7 +33,6 @@ class hashi_stack::repo (
architecture => 'amd64', architecture => 'amd64',
comment => $description, comment => $description,
location => 'https://apt.releases.hashicorp.com', location => 'https://apt.releases.hashicorp.com',
release => 'stable',
repos => 'main', repos => 'main',
key => { key => {
'id' => $key_id, 'id' => $key_id,

View file

@ -6,12 +6,16 @@ describe 'hashi_stack::repo class' do
# Using puppet_apply as a helper # Using puppet_apply as a helper
it 'should work with no errors based on the example' do it 'should work with no errors based on the example' do
pp = <<-EOS pp = <<-EOS
class { 'hashi_stack::repo': } include hashi_stack::repo
package { 'packer':
ensure => installed,
require => Class['Hashi_stack::Repo'],
}
EOS EOS
# Run it twice and test for idempotency # Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1) apply_manifest(pp, catch_failures: true)
expect(apply_manifest(pp).exit_code).to eq(0) apply_manifest(pp, catch_changes: true)
end end
end end
end end

View file

@ -3,6 +3,14 @@ require 'spec_helper'
describe 'hashi_stack::repo' do describe 'hashi_stack::repo' do
on_supported_os.each do |os, os_facts| on_supported_os.each do |os, os_facts|
context "on #{os}" do context "on #{os}" do
let(:facts) { os_facts }
case os_facts[:os]['family']
when 'Debian'
it { is_expected.to contain_apt__source('HashiCorp') }
when 'RedHat'
it { is_expected.to contain_yumrepo('HashiCorp') }
end
end end
end end
end end