Skip to content

Commit

Permalink
Remove puppet applications support
Browse files Browse the repository at this point in the history
  • Loading branch information
nabertrand committed May 4, 2023
1 parent f4c5c71 commit 1ddeb5c
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 172 deletions.
67 changes: 4 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* [Configuration](#configuration)
* [Naming conventions](#naming-conventions)
* [Example groups](#example-groups)
* [Defined Types, Classes & Applications](#defined-types-classes--applications)
* [Defined Types and Classes](#defined-types-and-classes)
* [Functions](#functions)
* [Hiera integration](#hiera-integration)
* [Producing coverage reports](#producing-coverage-reports)
Expand Down Expand Up @@ -259,9 +259,6 @@ structure and naming convention.
├── defines/
│ └── <define_name>_spec.rb
├── applications/
│ └── <application_name>_spec.rb
├── functions/
│ └── <function_name>_spec.rb
Expand Down Expand Up @@ -289,10 +286,6 @@ describe 'mydefine', :type => :define do
...
end

describe 'myapplication', :type => :application do
...
end

describe 'myfunction', :type => :puppet_function do
...
end
Expand All @@ -310,7 +303,7 @@ describe 'myhost.example.com', :type => :host do
end
```

## Defined Types, Classes & Applications
## Defined Types and Classes

### Matchers

Expand Down Expand Up @@ -601,7 +594,7 @@ let(:title) { 'foo' }

#### Specifying the parameters to pass to a resources or parameterised class

Parameters of a defined type, class or application can be passed defining `:params` in a let,
Parameters of a defined type or class can be passed defining `:params` in a let,
and passing it a hash as seen below.

```ruby
Expand All @@ -621,7 +614,7 @@ let(:params) { {'password' =>sensitive('secret') } }
```

For references to nodes or resources as seen when using `require` or `before` properties,
or an `application` resource you can pass the string as an argument to the `ref` helper:
you can pass the string as an argument to the `ref` helper:

```ruby
let(:params) { 'require' => ref('Package', 'sudoku') }
Expand All @@ -633,18 +626,6 @@ Which translates to:
mydefine { 'mytitle': require => Package['sudoku'] }
```

Another example, for an application setup (when using `app_management`):

```ruby
let(:params) { { 'nodes' => { ref('Node', 'dbnode') => ref('Myapp::Mycomponent', 'myapp') } } }
```

Will translate to:

```puppet
site { myapp { 'myimpl': nodes => { Node['dbnode'] => Myapp::Mycomponent['myimpl'] } } }
```

#### Specifying the FQDN of the test node

If the manifest you're testing expects to run on host with a particular name,
Expand Down Expand Up @@ -835,46 +816,6 @@ You can also use `exported_resources` directly in a test:
it { expect(exported_resources).to contain_file('foo') }
```

#### Testing applications

Applications in some ways behave as defined resources, but are more complex so
require a number of elements already documented above to be combined for testing.

A full example of the simplest rspec test for a single component application:

```ruby
require 'spec_helper'

describe 'orch_app' do
let(:node) { 'my_node' }
let(:title) { 'my_awesome_app' }
let(:params) do
{
'nodes' => {
ref('Node', node) => ref('Orch_app::Db', title),
}
}
end

it { should compile }
it { should contain_orch_app(title) }
end
```

Each piece is required:

* You must turn on app_management during testing for the handling to work
* The `:node` definition is required to be set so later on you can reference it in the `:nodes` argument within `:params`
* Applications act like defined resources, and each require a `:title` to be defined
* The `:nodes` key in `:params` requires the use of node reference mappings to resource
mappings. The `ref` keyword allows you to provide these (a normal string will not work).

Beyond these requirements, the very basic `should compile` test and other matchers
as you would expect will work the same as classes and defined resources.

**Note:** for the moment, cross-node support is not available and will return an error.
Ensure you model your tests to be single-node for the time being.

## Functions

### Matchers
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace :test do
if t.respond_to?(:exclude_pattern)
t.exclude_pattern = 'spec/fixtures/**/*_spec.rb'
else
t.pattern = 'spec/{applications,classes,defines,functions,hosts,type_aliases,types,unit}/**/*_spec.rb'
t.pattern = 'spec/{classes,defines,functions,hosts,type_aliases,types,unit}/**/*_spec.rb'
end
end

Expand Down
62 changes: 0 additions & 62 deletions docs/documentation/applications/index.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ cards:
path: /documentation/hosts/
icon: fa fa-server
colour: orange
-
title: Testing Applications
text:
path: /documentation/applications/
icon: fa fa-cubes
colour: green
-
title: Testing Types
text:
Expand Down
2 changes: 0 additions & 2 deletions lib/rspec-puppet/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'rspec-puppet/example/type_example_group'
require 'rspec-puppet/example/type_alias_example_group'
require 'rspec-puppet/example/provider_example_group'
require 'rspec-puppet/example/application_example_group'

RSpec.configure do |c|
def c.rspec_puppet_include(group, type, file_path)
Expand All @@ -25,7 +24,6 @@ def c.rspec_puppet_include(group, type, file_path)
c.rspec_puppet_include RSpec::Puppet::TypeExampleGroup, :type, %w[spec types]
c.rspec_puppet_include RSpec::Puppet::TypeAliasExampleGroup, :type_alias, %w[spec type_aliases]
c.rspec_puppet_include RSpec::Puppet::ProviderExampleGroup, :provider, %w[spec providers]
c.rspec_puppet_include RSpec::Puppet::ApplicationExampleGroup, :application, %w[spec applications]

# Hook for each example group type to remove any caches or instance variables, since they will remain
# and cause a memory leak. Can't be assigned per type by :file_path, so check for its presence.
Expand Down
21 changes: 0 additions & 21 deletions lib/rspec-puppet/example/application_example_group.rb

This file was deleted.

9 changes: 1 addition & 8 deletions lib/rspec-puppet/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def guess_type_from_path(path)
:type_alias
when %r{spec/provider}
:provider
when %r{spec/applications}
:application
else
:unknown
end
Expand Down Expand Up @@ -177,11 +175,6 @@ def test_manifest(type, opts = {})
else
"class { '#{class_name}': #{param_str(opts[:params])} }"
end
when :application
raise ArgumentError, 'You need to provide params for an application' unless opts.key?(:params)

"site { #{class_name} { #{sanitise_resource_title(title)}: #{param_str(opts[:params])} } }"

when :define
title_str = if title.is_a?(Array)
'[' + title.map { |r| sanitise_resource_title(r) }.join(', ') + ']'
Expand All @@ -207,7 +200,7 @@ def sanitise_resource_title(title)
def nodename(type)
return node if respond_to?(:node)

if %i[class define function application].include? type
if %i[class define function].include? type
Puppet[:certname]
else
class_name
Expand Down
3 changes: 0 additions & 3 deletions spec/fixtures/modules/orch_app/manifests/db.pp

This file was deleted.

6 changes: 0 additions & 6 deletions spec/fixtures/modules/orch_app/manifests/init.pp

This file was deleted.

0 comments on commit 1ddeb5c

Please sign in to comment.