1 |
ee942928
|
Tom McKay
|
require 'simplecov'
|
2 |
|
|
require 'pathname'
|
3 |
7b00acc6
|
Tom McKay
|
require 'stringio'
|
4 |
|
|
require 'tempfile'
|
5 |
ee942928
|
Tom McKay
|
|
6 |
|
|
SimpleCov.use_merging true
|
7 |
|
|
SimpleCov.start do
|
8 |
|
|
command_name 'MiniTest'
|
9 |
|
|
add_filter 'test'
|
10 |
|
|
end
|
11 |
|
|
SimpleCov.root Pathname.new(File.dirname(__FILE__) + "../../../")
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
require 'minitest/autorun'
|
15 |
|
|
require 'minitest/spec'
|
16 |
|
|
require "minitest-spec-context"
|
17 |
|
|
require "mocha/setup"
|
18 |
|
|
|
19 |
bf81b9cf
|
Tom McKay
|
require 'hammer_cli'
|
20 |
|
|
require 'hammer_cli_foreman/commands'
|
21 |
|
|
|
22 |
|
|
HammerCLI::Settings.load_from_file 'test/config.yml'
|
23 |
|
|
|
24 |
ee942928
|
Tom McKay
|
require 'hammer_cli_csv'
|
25 |
bfc065ce
|
Tom McKay
|
require 'hammer_cli_foreman'
|
26 |
bf81b9cf
|
Tom McKay
|
require 'hammer_cli_katello'
|
27 |
ee942928
|
Tom McKay
|
|
28 |
561a8ac9
|
Tom McKay
|
module HammerCLIForeman
|
29 |
|
|
def self.clear_credentials
|
30 |
|
|
@credentials = nil
|
31 |
|
|
end
|
32 |
bfc065ce
|
Tom McKay
|
end
|
33 |
|
|
|
34 |
561a8ac9
|
Tom McKay
|
|
35 |
dcfb98fd
|
Tom McKay
|
def hammer(context=nil)
|
36 |
561a8ac9
|
Tom McKay
|
HammerCLI::MainCommand.new("", context || HammerCLI::Settings.dump)
|
37 |
bfc065ce
|
Tom McKay
|
end
|
38 |
|
|
|
39 |
|
|
def capture
|
40 |
|
|
old_stdout = $stdout
|
41 |
|
|
old_stderr = $stderr
|
42 |
|
|
$stdout = stdout = StringIO.new
|
43 |
|
|
$stderr = stderr = StringIO.new
|
44 |
|
|
yield
|
45 |
|
|
[stdout.string, stderr.string]
|
46 |
|
|
ensure
|
47 |
|
|
$stdout = old_stdout
|
48 |
|
|
$stderr = old_stderr
|
49 |
|
|
end
|
50 |
|
|
|
51 |
|
|
def set_user(username, password='changeme')
|
52 |
561a8ac9
|
Tom McKay
|
HammerCLI::Connection.drop_all
|
53 |
|
|
HammerCLIForeman.clear_credentials
|
54 |
bfc065ce
|
Tom McKay
|
HammerCLI::Settings.load({
|
55 |
561a8ac9
|
Tom McKay
|
:_params => {
|
56 |
|
|
:username => username,
|
57 |
|
|
:password => password
|
58 |
|
|
},
|
59 |
|
|
:foreman => {
|
60 |
|
|
:username => username,
|
61 |
|
|
:password => password
|
62 |
|
|
},
|
63 |
|
|
:csv => {
|
64 |
|
|
:username => username,
|
65 |
|
|
:password => password
|
66 |
|
|
}
|
67 |
|
|
})
|
68 |
ee942928
|
Tom McKay
|
end
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
|
73 |
|
|
require File.join(File.dirname(__FILE__), 'helpers/command')
|
74 |
|
|
require File.join(File.dirname(__FILE__), 'helpers/resource_disabled') |