-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from evgeni/curl_command
add curl_command as serverspec extension
- Loading branch information
Showing
11 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'voxpupuli-acceptance', path: '../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'voxpupuli/acceptance/rake' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class defaults_serverspec { | ||
package {'nginx': | ||
ensure => present | ||
} | ||
service {'nginx': | ||
ensure => running | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "voxpupuliacceptancetests-defaults_serverspec", | ||
"version": "0.0.1", | ||
"author": "Vox Pupuli", | ||
"license": "Apache-2.0", | ||
"summary": "The voxpupuli-acceptance test suite defaults_serverspec", | ||
"description": "test the serverspec extensions shipped in voxpupuli-acceptance", | ||
"source": "https://github.com/voxpupuli/voxpupuli-acceptance", | ||
"project_page": "https://github.com/voxpupuli/voxpupuli-acceptance", | ||
"issues_url": "https://github.com/voxpupuli/voxpupuli-acceptance/issues", | ||
"dependencies": [], | ||
"requirements": [], | ||
"operatingsystem_support": [] | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/defaults_serverspec/spec/acceptance/basic_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'Basic integration test' do | ||
it_behaves_like 'an idempotent resource' do | ||
let(:manifest) { 'include defaults_serverspec' } | ||
end | ||
|
||
describe curl_command('http://localhost') do | ||
its(:response_code) { is_expected.to eq(200) } | ||
its(:exit_status) { is_expected.to eq 0 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'voxpupuli/acceptance/spec_helper_acceptance' | ||
|
||
configure_beaker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'serverspec' | ||
require_relative 'serverspec_extensions/curl_command' | ||
|
||
module Serverspec | ||
module Helper | ||
module Type | ||
def curl_command(*args) | ||
Voxpupuli::Acceptance::ServerspecExtensions::CurlCommand.new(*args) | ||
end | ||
end | ||
end | ||
end |
58 changes: 58 additions & 0 deletions
58
lib/voxpupuli/acceptance/serverspec_extensions/curl_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# written by https://github.com/ekohl | ||
# https://github.com/mizzy/serverspec/pull/611 was rejected so adding it here. | ||
|
||
require 'serverspec' | ||
|
||
module Voxpupuli | ||
module Acceptance | ||
module ServerspecExtensions | ||
class CurlCommand < Serverspec::Type::Command | ||
def response_code | ||
m = %r{Response-Code: (?<code>\d+)}.match(stderr) | ||
return 0 unless m | ||
|
||
m[:code].to_i | ||
end | ||
|
||
def body | ||
command_result.stdout | ||
end | ||
|
||
def body_as_json | ||
MultiJson.load(body) | ||
end | ||
|
||
private | ||
|
||
def curl_command | ||
# curl supports %{stderr} to --write-out since 7.63.0 | ||
# so the following doesn't work on EL8, which has curl 7.61.1 | ||
command = "curl --silent --write-out '%{stderr}Response-Code: %{response_code}\\n' '#{@name}'" | ||
|
||
@options.each do |option, value| | ||
case option | ||
when :cacert, :cert, :key | ||
command += " --#{option} '#{value}'" | ||
when :headers | ||
value.each do |header, header_value| | ||
command += if header_value | ||
" --header '#{header}: #{header_value}'" | ||
else | ||
" --header '#{header};'" | ||
end | ||
end | ||
else | ||
raise "Unknown option #{option} (value: #{value})" | ||
end | ||
end | ||
|
||
command | ||
end | ||
|
||
def command_result | ||
@command_result ||= @runner.run_command(curl_command) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters