onceover 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -2
- data/controlrepo.gemspec +1 -1
- data/lib/onceover/cli.rb +1 -1
- data/lib/onceover/cli/run.rb +2 -2
- data/lib/onceover/controlrepo.rb +38 -7
- data/lib/onceover/rake_tasks.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9cca70e7c3e4acba9f3a2aa60ae16087f30261f
|
4
|
+
data.tar.gz: e1f6255a54a6be2d9985b57bc82ca97bc7487bf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af61ee99bc06e538611e109157b9e328f53d02b2b6a1eddd0af6a1841cc65f065b131e3792e64767bb4d53a2df9a0c7255c79e0753b829402db2e677545c84f
|
7
|
+
data.tar.gz: 888e3c95a2630cbc47016af32084ef402f0c928e6b2ce3b46003a3828000e8d8f0a1a6c6b37581c4391d5c2e049a36a5805a8b89add7411d558819f04a6273a8
|
data/README.md
CHANGED
@@ -19,6 +19,7 @@ Onceover is a tool to automatically run basic tests on an entire Puppet controlr
|
|
19
19
|
- [Acceptance testing](#acceptance-testing)
|
20
20
|
- [Using Workarounds](#using-workarounds)
|
21
21
|
- [Extra tooling](#extra-tooling)
|
22
|
+
- [Accessing Onceover in a traditional RSpec test](#accessing-onceover-in-a-traditional-rspec-test)
|
22
23
|
- [Accessing fact sets in a traditional RSpec test](#accessing-fact-sets-in-a-traditional-rspec-test)
|
23
24
|
- [Accessing Roles in a traditional RSpec test](#accessing-roles-in-a-traditional-rspec-test)
|
24
25
|
- [Filtering](#filtering)
|
@@ -369,6 +370,32 @@ Here we are specifying custom commands to run for starting, stopping and checkin
|
|
369
370
|
|
370
371
|
Is this all too simple for you? Great! This is supposed to be a gateway to writing your own super-awesome really complicated tests using more traditional tools. If you want to ditch this tool in favour of doing it yourself, go ahead, but take these ruby methods as a parting gift:
|
371
372
|
|
373
|
+
### Accessing Onceover in a traditional RSpec test
|
374
|
+
|
375
|
+
If you would like to use `onceover.yaml` to manage which tests you want to run, but want more than just `it { should_compile }` tests to be run you can write you own as follows:
|
376
|
+
|
377
|
+
```ruby
|
378
|
+
# spec/classes/role_spec.rb
|
379
|
+
require 'spec_helper'
|
380
|
+
require 'onceover/controlrepo'
|
381
|
+
require 'helpers/shared_examples'
|
382
|
+
|
383
|
+
Onceover::Controlrepo.new.spec_tests do |class_name,node_name,facts,pre_conditions|
|
384
|
+
describe class_name do
|
385
|
+
context "on #{node_name}" do
|
386
|
+
let(:facts) { facts }
|
387
|
+
let(:pre_condition) { pre_conditions }
|
388
|
+
|
389
|
+
it_behaves_like 'soe'
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
```
|
394
|
+
|
395
|
+
This will use the `soe` [shared example](https://www.relishapp.com/rspec/rspec-core/docs/example-groups/shared-examples) on all of the tests that are configured in your `onceover.yaml` including any [pre_conditions](#using-workarounds) that you have set up.
|
396
|
+
|
397
|
+
**Note:** Onceover will automatically run any extra Rspec tests that it finds in the normal directories `spec/{classes,defines,unit,functions,hosts,integration,types}` so you can easily use auto-generated spec tests in conjunction with your own Rspec tests.
|
398
|
+
|
372
399
|
### Accessing fact sets in a traditional RSpec test
|
373
400
|
|
374
401
|
We can access all of our fact sets using `Onceover::Controlrepo.facts`. Normally it would be implemented something like this:
|
@@ -382,9 +409,9 @@ Onceover::Controlrepo.facts.each do |facts|
|
|
382
409
|
end
|
383
410
|
```
|
384
411
|
|
385
|
-
###
|
412
|
+
### Other (possibly less useful) methods
|
386
413
|
|
387
|
-
The following code will test all roles on all nodes in native rspec:
|
414
|
+
The following code will test all roles that onceover can find (ignoring the ones configured in `onceover.yaml`) on all nodes in native rspec:
|
388
415
|
|
389
416
|
```ruby
|
390
417
|
require 'spec_helper'
|
data/controlrepo.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "onceover"
|
6
|
-
s.version = "3.0.
|
6
|
+
s.version = "3.0.5"
|
7
7
|
s.authors = ["Dylan Ratcliffe"]
|
8
8
|
s.email = ["dylan.ratcliffe@puppet.com"]
|
9
9
|
s.homepage = "https://github.com/dylanratcliffe/onceover"
|
data/lib/onceover/cli.rb
CHANGED
@@ -25,7 +25,7 @@ class Onceover
|
|
25
25
|
optional nil, :nodeset_file, 'YAML file containing node definitions'
|
26
26
|
optional nil, :tempdir, 'Temp directory to use, defaults to .controlrepo'
|
27
27
|
optional nil, :manifest, 'Path fo find manifests'
|
28
|
-
optional nil, :
|
28
|
+
optional nil, :onceover_yaml, 'Path of controlrepo.yaml'
|
29
29
|
|
30
30
|
run do |opts, args, cmd|
|
31
31
|
puts cmd.help(:verbose => opts[:verbose])
|
data/lib/onceover/cli/run.rb
CHANGED
@@ -38,7 +38,7 @@ This includes deploying using r10k and running all custom tests.
|
|
38
38
|
|
39
39
|
run do |opts, args, cmd|
|
40
40
|
repo = Onceover::Controlrepo.new(opts)
|
41
|
-
runner = Onceover::Runner.new(repo,Onceover::TestConfig.new(repo.
|
41
|
+
runner = Onceover::Runner.new(repo,Onceover::TestConfig.new(repo.onceover_yaml,opts),:spec)
|
42
42
|
runner.prepare!
|
43
43
|
runner.run_spec!
|
44
44
|
end
|
@@ -55,7 +55,7 @@ This includes deploying using r10k and running all custom tests.
|
|
55
55
|
|
56
56
|
run do |opts, args, cmd|
|
57
57
|
repo = Onceover::Controlrepo.new(opts)
|
58
|
-
runner = Onceover::Runner.new(repo,Onceover::TestConfig.new(repo.
|
58
|
+
runner = Onceover::Runner.new(repo,Onceover::TestConfig.new(repo.onceover_yaml,opts),:acceptance)
|
59
59
|
runner.prepare!
|
60
60
|
runner.run_acceptance!
|
61
61
|
end
|
data/lib/onceover/controlrepo.rb
CHANGED
@@ -28,7 +28,7 @@ class Onceover
|
|
28
28
|
attr_accessor :nodeset_file
|
29
29
|
attr_accessor :manifest
|
30
30
|
attr_accessor :tempdir
|
31
|
-
attr_accessor :
|
31
|
+
attr_accessor :onceover_yaml
|
32
32
|
attr_accessor :opts
|
33
33
|
|
34
34
|
# Create methods on self so that we can access these basic things without
|
@@ -83,7 +83,22 @@ class Onceover
|
|
83
83
|
|
84
84
|
def initialize(opts = {})
|
85
85
|
# When we initialize the object it is going to set some instance vars
|
86
|
-
|
86
|
+
|
87
|
+
# We want people to be able to run this from anywhere within the repo
|
88
|
+
# so traverse up until we think we are in a controlrepo.
|
89
|
+
if opts[:path]
|
90
|
+
@root = opts[:path]
|
91
|
+
else
|
92
|
+
@root = Dir.pwd
|
93
|
+
until File.exist?(File.expand_path('./environment.conf',@root)) do
|
94
|
+
# Throw an exception if we can't go any further up
|
95
|
+
throw "Could not file root of the controlrepo anywhere above #{Dir.pwd}" if @root == File.expand_path('../',@root)
|
96
|
+
|
97
|
+
# Step up and try again
|
98
|
+
@root = File.expand_path('../',@root)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
87
102
|
@environmentpath = opts[:environmentpath] || 'etc/puppetlabs/code/environments'
|
88
103
|
@puppetfile = opts[:puppetfile] || File.expand_path('./Puppetfile',@root)
|
89
104
|
@environment_conf = opts[:environment_conf] || File.expand_path('./environment.conf',@root)
|
@@ -93,10 +108,10 @@ class Onceover
|
|
93
108
|
@nodeset_file = opts[:nodeset_file] || File.expand_path('./spec/acceptance/nodesets/onceover-nodes.yml',@root)
|
94
109
|
@role_regex = /role[s]?:{2}/
|
95
110
|
@profile_regex = /profile[s]?:{2}/
|
96
|
-
@tempdir = opts[:tempdir] ||
|
111
|
+
@tempdir = opts[:tempdir] || File.expand_path('./.onceover',@root)
|
97
112
|
$temp_modulepath = nil
|
98
113
|
@manifest = opts[:manifest] || config['manifest'] ? File.expand_path(config['manifest'],@root) : nil
|
99
|
-
@
|
114
|
+
@onceover_yaml = opts[:onceover_yaml] || "#{@spec_dir}/onceover.yaml"
|
100
115
|
@opts = opts
|
101
116
|
logger.level = :debug if @opts[:debug]
|
102
117
|
end
|
@@ -113,7 +128,7 @@ class Onceover
|
|
113
128
|
#{'nodeset_file'.green} #{@nodeset_file}
|
114
129
|
#{'roles'.green} #{roles}
|
115
130
|
#{'profiles'.green} #{profiles}
|
116
|
-
#{'
|
131
|
+
#{'onceover.yaml'.green} #{@onceover_yaml}
|
117
132
|
END
|
118
133
|
end
|
119
134
|
|
@@ -371,7 +386,7 @@ class Onceover
|
|
371
386
|
require 'pathname'
|
372
387
|
require 'colored'
|
373
388
|
|
374
|
-
Onceover::Controlrepo.init_write_file(
|
389
|
+
Onceover::Controlrepo.init_write_file(generate_onceover_yaml(repo),repo.onceover_yaml)
|
375
390
|
Onceover::Controlrepo.init_write_file(generate_nodesets(repo),repo.nodeset_file)
|
376
391
|
Onceover::Controlrepo.init_write_file(Onceover::Controlrepo.evaluate_template('pre_conditions_README.md.erb',binding),File.expand_path('./pre_conditions/README.md',repo.spec_dir))
|
377
392
|
Onceover::Controlrepo.init_write_file(Onceover::Controlrepo.evaluate_template('factsets_README.md.erb',binding),File.expand_path('./factsets/README.md',repo.spec_dir))
|
@@ -393,7 +408,7 @@ class Onceover
|
|
393
408
|
end
|
394
409
|
end
|
395
410
|
|
396
|
-
def self.
|
411
|
+
def self.generate_onceover_yaml(repo)
|
397
412
|
# This will return a controlrepo.yaml that can be written to a file
|
398
413
|
Onceover::Controlrepo.evaluate_template('controlrepo.yaml.erb',binding)
|
399
414
|
end
|
@@ -466,6 +481,22 @@ class Onceover
|
|
466
481
|
end
|
467
482
|
end
|
468
483
|
|
484
|
+
# Returns the deduplicted and verified output of testconfig.spec_tests for
|
485
|
+
# use in Rspec tests so that we don't have to deal with more than one object
|
486
|
+
def spec_tests(&block)
|
487
|
+
require 'onceover/testconfig'
|
488
|
+
|
489
|
+
# Load up all of the tests and deduplicate them
|
490
|
+
testconfig = Onceover::TestConfig.new(@onceover_yaml,@opts)
|
491
|
+
testconfig.spec_tests.each { |tst| testconfig.verify_spec_test(self,tst) }
|
492
|
+
tests = testconfig.run_filters(Onceover::Test.deduplicate(testconfig.spec_tests))
|
493
|
+
|
494
|
+
# Loop over each test, executing the user's block on each
|
495
|
+
tests.each do |tst|
|
496
|
+
block.call(tst.classes[0].name,tst.nodes[0].name,tst.nodes[0].fact_set,testconfig.pre_condition)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
469
500
|
private
|
470
501
|
|
471
502
|
def read_facts(facts_file)
|
data/lib/onceover/rake_tasks.rb
CHANGED
@@ -29,12 +29,12 @@ task :controlrepo_details do
|
|
29
29
|
puts Onceover::Controlrepo.new.to_s
|
30
30
|
end
|
31
31
|
|
32
|
-
task :
|
32
|
+
task :generate_onceover_yaml do
|
33
33
|
require 'onceover/controlrepo'
|
34
34
|
repo = Onceover::Controlrepo.new
|
35
35
|
template_dir = File.expand_path('../../templates',File.dirname(__FILE__))
|
36
|
-
|
37
|
-
puts ERB.new(
|
36
|
+
onceover_yaml_template = File.read(File.expand_path('./controlrepo.yaml.erb',template_dir))
|
37
|
+
puts ERB.new(onceover_yaml_template, nil, '-').result(binding)
|
38
38
|
end
|
39
39
|
|
40
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onceover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Ratcliffe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|