-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add curl_command as serverspec extension #89
Open
evgeni
wants to merge
2
commits into
voxpupuli:master
Choose a base branch
from
evgeni:curl_command
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
require 'voxpupuli/acceptance/spec_helper_acceptance' | ||
require 'voxpupuli/acceptance/serverspec_extensions' | ||
|
||
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 | ||
evgeni marked this conversation as resolved.
Show resolved
Hide resolved
|
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: serverspec itself now depends on |
||
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}'" | ||
ekohl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be added to
spec_helper_acceptance.rb
, or should people need to explicitly opt-in to it withThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makese sense to load it by default? It's not expensive and makes the usage easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only worry is that it modifies serverspec without the user opting in for that.
But I would also lean towards "enable"
@ekohl?