hammer_cli_foreman_webhooks 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/hammer_cli_foreman_webhooks/version.rb +1 -1
- data/lib/hammer_cli_foreman_webhooks/webhook.rb +6 -5
- data/lib/hammer_cli_foreman_webhooks/webhook_template.rb +15 -0
- data/test/data/3.3/foreman_api.json +1 -0
- data/test/functional/test_helper.rb +11 -0
- data/test/functional/webhook_template_test.rb +63 -0
- data/test/functional/webhook_test.rb +126 -0
- data/test/test_helper.rb +18 -0
- metadata +16 -7
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
+
|
3
|
+
require 'hammer_cli/testing/output_matchers'
|
4
|
+
require 'hammer_cli/testing/command_assertions'
|
5
|
+
require 'hammer_cli/testing/data_helpers'
|
6
|
+
require 'hammer_cli_foreman/testing/api_expectations'
|
7
|
+
|
8
|
+
include HammerCLI::Testing::OutputMatchers
|
9
|
+
include HammerCLI::Testing::CommandAssertions
|
10
|
+
include HammerCLI::Testing::DataHelpers
|
11
|
+
include HammerCLIForeman::Testing::APIExpectations
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'webhook template' do
|
4
|
+
describe 'import' do
|
5
|
+
let(:template) do
|
6
|
+
{
|
7
|
+
'id' => 1,
|
8
|
+
'template' => 'Template content'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
let(:cmd) { %w(webhook-template import) }
|
12
|
+
let(:tempfile) { Tempfile.new('template') }
|
13
|
+
|
14
|
+
it 'requires --name and --file' do
|
15
|
+
params = ['--name=test']
|
16
|
+
api_expects_no_call
|
17
|
+
expected_result = usage_error_result(
|
18
|
+
cmd,
|
19
|
+
'Options --name, --file are required.',
|
20
|
+
'Could not import the webhook template')
|
21
|
+
result = run_cmd(cmd + params)
|
22
|
+
assert_cmd(expected_result, result)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'import template' do
|
26
|
+
params = ['--name=test', "--file=#{tempfile.path}"]
|
27
|
+
tempfile.write('Template content')
|
28
|
+
tempfile.rewind
|
29
|
+
api_expects(:webhook_templates, :import, 'Import webhook template').with_params(
|
30
|
+
'webhook_template' => {
|
31
|
+
'name' => 'test',
|
32
|
+
'template' => 'Template content'
|
33
|
+
}).returns(template)
|
34
|
+
|
35
|
+
result = run_cmd(cmd + params)
|
36
|
+
assert_cmd(success_result("Imported webhook template successfully.\n"), result)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'export' do
|
41
|
+
let(:cmd) { %w(webhook-template export) }
|
42
|
+
let(:tempfile) { Tempfile.new('template', '/tmp') }
|
43
|
+
let(:params) { ['--id=1', '--path=/tmp'] }
|
44
|
+
let(:template_response) do
|
45
|
+
response = mock('TemplateResponse')
|
46
|
+
response.stubs(:code).returns(200)
|
47
|
+
response.stubs(:body).returns('Template content')
|
48
|
+
response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
|
49
|
+
response
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'download template' do
|
53
|
+
api_expects(:webhook_templates, :export, 'Export webhook template').with_params(
|
54
|
+
'id' => '1').returns(template_response)
|
55
|
+
|
56
|
+
output = OutputMatcher.new("The webhook template has been saved to #{tempfile.path}")
|
57
|
+
expected_result = success_result(output)
|
58
|
+
result = run_cmd(cmd + params)
|
59
|
+
assert_cmd(expected_result, result)
|
60
|
+
assert_equal('Template content', tempfile.read)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'webhook' do
|
4
|
+
let(:base_cmd) { %w[webhook] }
|
5
|
+
let(:webhook) do
|
6
|
+
{
|
7
|
+
id: 1,
|
8
|
+
name: 'test',
|
9
|
+
target_url: 'https://app.example.com',
|
10
|
+
enabled: true,
|
11
|
+
event: 'user_created.event.foreman',
|
12
|
+
http_method: 'POST',
|
13
|
+
http_content_type: 'application/json',
|
14
|
+
webhook_template: { id: 1, name: 'test' },
|
15
|
+
user: 'admin',
|
16
|
+
verify_ssl: true,
|
17
|
+
proxy_authorization: true,
|
18
|
+
ssl_ca_certs: 'certs',
|
19
|
+
'http_headers' => '{"X-Shellhook-Arg-0":"test","X-Shellhook-Arg-1":"2"}',
|
20
|
+
created_at: '01/10/2022',
|
21
|
+
updated_at: '01/10/2022'
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'list' do
|
26
|
+
let(:cmd) { base_cmd << 'list' }
|
27
|
+
|
28
|
+
it 'should list all webhooks' do
|
29
|
+
api_expects(:webhooks, :index, 'List').with_params(
|
30
|
+
'page' => 1, 'per_page' => 1000
|
31
|
+
).returns(index_response([webhook]))
|
32
|
+
|
33
|
+
output = IndexMatcher.new(
|
34
|
+
[
|
35
|
+
['ID', 'NAME', 'TARGET URL', 'ENABLED'],
|
36
|
+
['1', 'test', 'https://app.example.com', 'yes']
|
37
|
+
]
|
38
|
+
)
|
39
|
+
expected_result = success_result(output)
|
40
|
+
|
41
|
+
result = run_cmd(cmd)
|
42
|
+
assert_cmd(expected_result, result)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'create' do
|
47
|
+
let(:cmd) { base_cmd << 'create' }
|
48
|
+
let(:params) do
|
49
|
+
%w[
|
50
|
+
--name=test --target-url=https://app.example.com --enabled=true
|
51
|
+
--event=user_created.event.foreman
|
52
|
+
--http-headers=X-Shellhook-Arg-0=test,X-Shellhook-Arg-1=2
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should create a webhook' do
|
57
|
+
api_expects(:webhooks, :create).with_params(
|
58
|
+
'webhook' => {
|
59
|
+
'target_url' => 'https://app.example.com', 'name' => 'test',
|
60
|
+
'enabled' => true, 'event' => 'user_created.event.foreman',
|
61
|
+
'http_headers' => '{"X-Shellhook-Arg-0":"test","X-Shellhook-Arg-1":"2"}'
|
62
|
+
}
|
63
|
+
).returns(webhook)
|
64
|
+
|
65
|
+
expected_result = success_result("Webhook [test] created.\n")
|
66
|
+
|
67
|
+
result = run_cmd(cmd + params)
|
68
|
+
assert_cmd(expected_result, result)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'update' do
|
73
|
+
let(:cmd) { base_cmd << 'update' }
|
74
|
+
let(:params) do
|
75
|
+
%w[
|
76
|
+
--id=1 --target-url=https://app.example.com --enabled=true
|
77
|
+
--event=user_created.event.foreman
|
78
|
+
--http-headers=X-Shellhook-Arg-0=test,X-Shellhook-Arg-1=2
|
79
|
+
]
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should update a webhook' do
|
83
|
+
api_expects(:webhooks, :update).with_params(
|
84
|
+
'id' => '1',
|
85
|
+
'webhook' => {
|
86
|
+
'target_url' => 'https://app.example.com',
|
87
|
+
'enabled' => true, 'event' => 'user_created.event.foreman',
|
88
|
+
'http_headers' => '{"X-Shellhook-Arg-0":"test","X-Shellhook-Arg-1":"2"}'
|
89
|
+
}
|
90
|
+
).returns(webhook)
|
91
|
+
|
92
|
+
expected_result = success_result("Webhook [test] updated.\n")
|
93
|
+
|
94
|
+
result = run_cmd(cmd + params)
|
95
|
+
assert_cmd(expected_result, result)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'info' do
|
100
|
+
let(:cmd) { base_cmd << 'info' }
|
101
|
+
let(:params) { %w[--id=1] }
|
102
|
+
|
103
|
+
it 'should show a webhook' do
|
104
|
+
api_expects(:webhooks, :show, 'Show').with_params('id' => '1').returns(webhook)
|
105
|
+
|
106
|
+
expected_result = success_result(/X-Shellhook-Arg-0/)
|
107
|
+
|
108
|
+
result = run_cmd(cmd + params)
|
109
|
+
assert_cmd(expected_result, result)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'delete' do
|
114
|
+
let(:cmd) { base_cmd << 'delete' }
|
115
|
+
let(:params) { %w[--id=1] }
|
116
|
+
|
117
|
+
it 'should delete a webhook' do
|
118
|
+
api_expects(:webhooks, :destroy, 'Delete').with_params('id' => '1').returns(webhook)
|
119
|
+
|
120
|
+
expected_result = success_result("Webhook [test] deleted.\n")
|
121
|
+
|
122
|
+
result = run_cmd(cmd + params)
|
123
|
+
assert_cmd(expected_result, result)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
ENV['TEST_API_VERSION'] = ENV['TEST_API_VERSION'] || '3.3'
|
2
|
+
FOREMAN_WEBHOOKS_VERSION = Gem::Version.new(ENV['TEST_API_VERSION']).to_s
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'minitest-spec-context'
|
7
|
+
require 'mocha/minitest'
|
8
|
+
require 'hammer_cli'
|
9
|
+
|
10
|
+
HammerCLI.context[:api_connection].create('foreman') do
|
11
|
+
HammerCLI::Apipie::ApiConnection.new(
|
12
|
+
apidoc_cache_dir: 'test/data/' + FOREMAN_WEBHOOKS_VERSION,
|
13
|
+
apidoc_cache_name: 'foreman_api',
|
14
|
+
dry_run: true
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'hammer_cli_foreman_webhooks'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammer_cli_foreman_webhooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleh Fedorenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hammer_cli_foreman
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 2.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 4.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 2.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 4.0.0
|
33
33
|
description:
|
34
34
|
email:
|
35
35
|
- ofedoren@redhat.com
|
@@ -46,6 +46,11 @@ files:
|
|
46
46
|
- lib/hammer_cli_foreman_webhooks/version.rb
|
47
47
|
- lib/hammer_cli_foreman_webhooks/webhook.rb
|
48
48
|
- lib/hammer_cli_foreman_webhooks/webhook_template.rb
|
49
|
+
- test/data/3.3/foreman_api.json
|
50
|
+
- test/functional/test_helper.rb
|
51
|
+
- test/functional/webhook_template_test.rb
|
52
|
+
- test/functional/webhook_test.rb
|
53
|
+
- test/test_helper.rb
|
49
54
|
homepage: https://github.com/theforeman/hammer-cli-foreman-webhooks
|
50
55
|
licenses:
|
51
56
|
- GPL-3.0
|
@@ -65,9 +70,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
70
|
- !ruby/object:Gem::Version
|
66
71
|
version: '0'
|
67
72
|
requirements: []
|
68
|
-
|
69
|
-
rubygems_version: 2.7.6.2
|
73
|
+
rubygems_version: 3.1.2
|
70
74
|
signing_key:
|
71
75
|
specification_version: 4
|
72
76
|
summary: Foreman Webhooks plugin for Hammer CLI
|
73
|
-
test_files:
|
77
|
+
test_files:
|
78
|
+
- test/data/3.3/foreman_api.json
|
79
|
+
- test/functional/test_helper.rb
|
80
|
+
- test/functional/webhook_template_test.rb
|
81
|
+
- test/functional/webhook_test.rb
|
82
|
+
- test/test_helper.rb
|