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

testconfig.rb : added excluded_dirs entry to the onceover.yaml file #190

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ Why an array of hashes? Well, that is so that we can refer to the same node or n

In the example below we have referred to `centos6a` and `centos7b` in all of our tests as they are in `all_nodes`, `non_windows_servers` and `centos_severs`. However we have *left the more specific references to last*. This is because entries in the test_matrix will override entries above them if applicable. Meaning that we are still only testing each class on the two Centos servers once (Because the gem does de-duplication before running the tests), but also making sure we run `roles::frontend_webserver` twice before checking for idempotency.

**functions** In this section we can add functions that we want to mock when running spec tests. Each function takes the following arguments:
**functions:** In this section we can add functions that we want to mock when running spec tests. Each function takes the following arguments:
- **returns** *Optional: A value to return*

- **returns** *Optional: A value to return*

**before and after conditions** We can set `before` and `after` blocks before each spec test. These are usually used when the functions to stub are conditional: stub functionx if the OS is windows, stub functiony if the fact java_installed is true. The facts are available through the `node_facts` hash and the trusted facts as `trusted_facts`.
**before and after conditions:** We can set `before` and `after` blocks before each spec test. These are usually used when the functions to stub are conditional: stub functionx if the OS is windows, stub functiony if the fact java_installed is true. The facts are available through the `node_facts` hash and the trusted facts as `trusted_facts`.

```yaml
before:
Expand All @@ -121,7 +120,7 @@ after:
- "puts 'Test finished running'"
```

**opts** The `opts` section overrides defaults for the `Onceover::Controlrepo` class' `opts` hash.
**opts:** The `opts` section overrides defaults for the `Onceover::Controlrepo` class' `opts` hash.

```yaml
opts:
Expand All @@ -140,7 +139,15 @@ opts:
- 'spec/factsets/*.facts'
```

A full example:
**excluded_dirs:** `excluded_dirs` are not copied during the onceover cache folder creation; adding big folder that are not required by the puppet code to this list will speed up test executions.
```yaml
excluded_dirs:
- .git
- .vagrant
- .venv
```

**A full example:**

```yaml
classes:
Expand Down Expand Up @@ -203,6 +210,9 @@ functions:
opts:
:facts_dirs:
- spec/factsets

excluded_dirs:
- .git
```

**Include/Exclude syntax:** This can be used with either `node_groups` or `class_groups` and allows us to save some time by using existing groups to create new ones e.g.
Expand Down
5 changes: 3 additions & 2 deletions lib/onceover/cli/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def self.command

run do |opts, args, cmd|
repo = Onceover::Controlrepo.new(opts)
Onceover::Deploy.new.deploy_local(repo, opts)
runner = Onceover::Runner.new(repo,Onceover::TestConfig.new(repo.onceover_yaml, opts), :spec)
config = Onceover::TestConfig.new(repo.onceover_yaml, opts)
Onceover::Deploy.new.deploy_local(repo, config, opts)
runner = Onceover::Runner.new(repo, config, :spec)
runner.prepare!
runner.run_spec!
end
Expand Down
4 changes: 2 additions & 2 deletions lib/onceover/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# handle local deployments (run r10k in .onceover dir)
class Onceover
class Deploy
def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
def deploy_local(repo, config, opts = {})
require 'onceover/controlrepo'
require 'pathname'

Expand All @@ -28,7 +28,7 @@ def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
#
# If there are more situations like this we can add them to this array as
# full paths
excluded_dirs = []
excluded_dirs = config.additional_excluded_dirs.map { |excluded_dir| Pathname.new("#{repo.root}/#{excluded_dir}") }
excluded_dirs << Pathname.new("#{repo.root}/.onceover")
excluded_dirs << Pathname.new(ENV['GEM_HOME']) if ENV['GEM_HOME']

Expand Down
2 changes: 2 additions & 0 deletions lib/onceover/testconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestConfig
attr_accessor :before_conditions
attr_accessor :after_conditions
attr_accessor :skip_r10k
attr_accessor :additional_excluded_dirs
attr_accessor :force
attr_accessor :strict_variables
attr_accessor :formatters
Expand Down Expand Up @@ -72,6 +73,7 @@ def initialize(file, opts = {})
# Initialise all of the groups
config['node_groups'].each { |name, members| @node_groups << Onceover::Group.new(name, members) } unless config['node_groups'] == nil
config['class_groups'].each { |name, members| @class_groups << Onceover::Group.new(name, members) } unless config['class_groups'] == nil
@additional_excluded_dirs = config['excluded_dirs'] || []

@filter_tags = opts[:tags] ? [opts[:tags].split(',')].flatten : nil
@filter_classes = opts[:classes] ? [opts[:classes].split(',')].flatten.map {|x| Onceover::Class.find(x)} : nil
Expand Down