pdqtest 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/pdqtest +10 -1
- data/lib/pdqtest/docker.rb +27 -2
- data/lib/pdqtest/instance.rb +2 -2
- data/lib/pdqtest/puppet.rb +68 -19
- data/lib/pdqtest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b859b1e69e60d862ea7bad7f5e163f09babeb03
|
4
|
+
data.tar.gz: 06eae870f12823b5bc51a14163c52229654de764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cea2599e6d6c22b56a7fd0285904618d448de6c195c2bedf1c721a157c19b5b21258fcfb1b8604be4bc00ccbff589d8293da4356390667070b71c7aa445844de
|
7
|
+
data.tar.gz: 893d79733f89deef23dbe53bc6b5bcce2ea9108536b0da082561ec6f8f43ac803a5733aeb0ea7a735c054744cbcd4b90cc08d2d4e81f2c16037ff5323727d2e5
|
data/exe/pdqtest
CHANGED
@@ -44,9 +44,18 @@ Escort::App.create do |app|
|
|
44
44
|
|
45
45
|
|
46
46
|
app.command :acceptance do |command|
|
47
|
+
command.options do |opts|
|
48
|
+
opts.opt(:example,
|
49
|
+
'Run only this example (eg --example examples/init.pp)',
|
50
|
+
:long => '--example',
|
51
|
+
:type => :string,
|
52
|
+
:default => nil,
|
53
|
+
)
|
54
|
+
end
|
47
55
|
command.action do |options, arguments|
|
48
56
|
PDQTest::Instance.set_keep_container(options[:global][:options][:keep_container])
|
49
|
-
|
57
|
+
example = options[:global][:commands][:acceptance][:options][:example]
|
58
|
+
PDQTest::Core.run(lambda {PDQTest::Instance.run(example)})
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
data/lib/pdqtest/docker.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PDQTest
|
2
2
|
module Docker
|
3
|
-
|
4
|
-
|
3
|
+
OUT = 0
|
4
|
+
ERR = 1
|
5
5
|
STATUS = 2
|
6
6
|
ENV='export TERM=xterm LC_ALL=C PATH=/usr/local/bats/bin:/opt/puppetlabs/puppet/bin:$PATH;'
|
7
7
|
IMAGE_NAME='geoffwilliams/pdqtest-centos:2017-01-08-0'
|
@@ -41,5 +41,30 @@ module PDQTest
|
|
41
41
|
end
|
42
42
|
status = allowable_values.include?(res[STATUS])
|
43
43
|
end
|
44
|
+
|
45
|
+
def self.exec_out(res)
|
46
|
+
res[OUT]
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.exec_err(res)
|
50
|
+
res[ERR]
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.log_out(res)
|
54
|
+
exec_out(res).each { |l|
|
55
|
+
# Output comes back as an array and needs to be iterated or we lose our
|
56
|
+
# ansi formatting
|
57
|
+
Escort::Logger.output.puts l
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.log_err(res)
|
62
|
+
exec_err(res).each { |l|
|
63
|
+
# Output comes back as an array and needs to be iterated or we lose our
|
64
|
+
# ansi formatting
|
65
|
+
Escort::Logger.error.error l
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
44
69
|
end
|
45
70
|
end
|
data/lib/pdqtest/instance.rb
CHANGED
@@ -21,14 +21,14 @@ module PDQTest
|
|
21
21
|
@@keep_container = keep_container
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.run
|
24
|
+
def self.run(example=nil)
|
25
25
|
# needed to prevent timeouts from container.exec()
|
26
26
|
Excon.defaults[:write_timeout] = 1000
|
27
27
|
Excon.defaults[:read_timeout] = 1000
|
28
28
|
|
29
29
|
@@active_container = PDQTest::Docker::new_container(TEST_DIR)
|
30
30
|
Escort::Logger.output.puts "alive, running tests"
|
31
|
-
status = PDQTest::Puppet.run(@@active_container)
|
31
|
+
status = PDQTest::Puppet.run(@@active_container, example)
|
32
32
|
|
33
33
|
if @@keep_container
|
34
34
|
Escort::Logger.output.puts "finished build, container #{@@active_container.id} left on system"
|
data/lib/pdqtest/puppet.rb
CHANGED
@@ -66,6 +66,7 @@ module PDQTest
|
|
66
66
|
def self.test_basename(t)
|
67
67
|
# remove examples/ and .pp
|
68
68
|
# eg ./examples/apache/mod/mod_php.pp --> apache/mod/mod_php
|
69
|
+
|
69
70
|
t.gsub(EXAMPLES_DIR + '/','').gsub('.pp','')
|
70
71
|
end
|
71
72
|
|
@@ -75,7 +76,7 @@ module PDQTest
|
|
75
76
|
Escort::Logger.output.puts "*** bats test **** bats #{PDQTest::Instance::TEST_DIR}/#{testcase}"
|
76
77
|
res = PDQTest::Docker.exec(container, "bats #{PDQTest::Instance::TEST_DIR}/#{testcase}")
|
77
78
|
status = PDQTest::Docker.exec_status(res)
|
78
|
-
|
79
|
+
PDQTest::Docker.log_out(res)
|
79
80
|
@@bats_executed << testcase
|
80
81
|
else
|
81
82
|
Escort::Logger.error.error "no #{suffix} tests for #{example} (should be at #{testcase})"
|
@@ -92,6 +93,8 @@ module PDQTest
|
|
92
93
|
script = File.read(setup)
|
93
94
|
res = PDQTest::Docker.exec(container, script)
|
94
95
|
status = PDQTest::Docker.exec_status(res)
|
96
|
+
PDQTest::Docker.log_out(res)
|
97
|
+
|
95
98
|
@@setup_executed << setup
|
96
99
|
else
|
97
100
|
Escort::Logger.output.puts "no setup file for #{example} (should be in #{setup})"
|
@@ -101,7 +104,49 @@ module PDQTest
|
|
101
104
|
status
|
102
105
|
end
|
103
106
|
|
104
|
-
def self.
|
107
|
+
def self.run_example(container, example)
|
108
|
+
if ! example.start_with?('./')
|
109
|
+
# must prepend ./ to the example or we will not match the correct regexp
|
110
|
+
# in test_basename
|
111
|
+
example = "./#{example}"
|
112
|
+
end
|
113
|
+
Escort::Logger.output.puts "testing #{example}"
|
114
|
+
status = false
|
115
|
+
|
116
|
+
if setup_test(container, example)
|
117
|
+
|
118
|
+
# see if we should run a bats test before running puppet
|
119
|
+
if bats_test(container, example, BEFORE_SUFFIX)
|
120
|
+
|
121
|
+
# run puppet apply - 1st run
|
122
|
+
res = PDQTest::Docker.exec(container, puppet_apply(example))
|
123
|
+
PDQTest::Docker.log_out(res)
|
124
|
+
if PDQTest::Docker.exec_status(res, true) # allow 2 as exit status
|
125
|
+
|
126
|
+
# run puppet apply - 2nd run (check for idempotencey/no more changes)
|
127
|
+
res = PDQTest::Docker.exec(container, puppet_apply(example))
|
128
|
+
PDQTest::Docker.log_out(res)
|
129
|
+
|
130
|
+
# run the bats test if nothing failed yet
|
131
|
+
if PDQTest::Docker.exec_status(res) # only allow 0 as exit status
|
132
|
+
status = bats_test(container, example, AFTER_SUFFIX)
|
133
|
+
else
|
134
|
+
Escort::Logger.error.error "Not idempotent: #{example}"
|
135
|
+
end
|
136
|
+
else
|
137
|
+
Escort::Logger.error.error "First puppet run of #{example} failed"
|
138
|
+
end
|
139
|
+
else
|
140
|
+
Escort::Logger.error.error "Bats tests to run before #{example} failed"
|
141
|
+
end
|
142
|
+
else
|
143
|
+
Escort::Logger.error.error "Setup script for #{example} failed"
|
144
|
+
end
|
145
|
+
|
146
|
+
status
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.run(container, example=nil)
|
105
150
|
status = true
|
106
151
|
Escort::Logger.output.puts "fetch deps"
|
107
152
|
res = PDQTest::Docker.exec(container, install_deps)
|
@@ -111,23 +156,27 @@ module PDQTest
|
|
111
156
|
res = PDQTest::Docker.exec(container, link_module)
|
112
157
|
status &= PDQTest::Docker.exec_status(res)
|
113
158
|
Escort::Logger.output.puts "run tests"
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
159
|
+
if example
|
160
|
+
status &= run_example(container, example)
|
161
|
+
else
|
162
|
+
find_examples.each { |e|
|
163
|
+
status &= run_example(container, e)
|
164
|
+
# Escort::Logger.output.puts "testing #{e} #{status}"
|
165
|
+
#
|
166
|
+
# status &= setup_test(container, e)
|
167
|
+
#
|
168
|
+
# # see if we should run a bats test before running puppet
|
169
|
+
# status &= bats_test(container, e, BEFORE_SUFFIX)
|
170
|
+
#
|
171
|
+
# # run puppet apply
|
172
|
+
# res = PDQTest::Docker.exec(container, puppet_apply(e))
|
173
|
+
# status &= PDQTest::Docker.exec_status(res, true)
|
174
|
+
# Escort::Logger.output.puts res
|
175
|
+
#
|
176
|
+
# # see if we should run a bats test after running puppet
|
177
|
+
# status &= bats_test(container, e, AFTER_SUFFIX)
|
178
|
+
}
|
179
|
+
end
|
131
180
|
status
|
132
181
|
end
|
133
182
|
|
data/lib/pdqtest/version.rb
CHANGED