diff options
author | Jordan Running <jr@getchef.com> | 2016-02-11 13:06:56 -0600 |
---|---|---|
committer | Jordan Running <jr@getchef.com> | 2016-02-24 13:35:19 -0600 |
commit | 2469894eab12f24893916b571a981e082dfe97df (patch) | |
tree | bc657d22f7f41dad46a68f9825189c2dd20053b9 /spec | |
parent | 86e99a48cc39a0b5c931c29fbfef9e196252c9c2 (diff) | |
download | chef-zero-2469894eab12f24893916b571a981e082dfe97df.tar.gz |
Make user and client keys endpoints pass Pedant specs
- Implement ActorKeyEndpoint, ActorKeysEndpoint.
- Implement user, client keys in `ActorEndpoint#delete`, `#put`.
- RestBase
- Fix RestErrorResponse exceptions to report actual `rest_path`
instead associated with the failed data store operation instead of
`request.rest_path`.
- Move `json_response`, `already_json_response` args `request_version`
and `response_version` into options hash; add docs.
- DataError, RestErrorResponse: Pass useful message text to `super`.
- RestRouter: Clean up logging
- Print request methods, paths and bodies more readably for log_level >= INFO.
- Pretty-print RestRequest objects (only printed when log_level == DEBUG).
- Server: Change default log_level to `:warn` (to enable logging cleanup above).
- `Rakefile`, `spec/run_oc_pedant.rb`
- Consume RSpec, Pedant options from `ENV['RSPEC_OPTS']`, `ENV['PEDANT_OPTS']` (see `rake -D`).
- Consume `ENV['LOG_LEVEL'` (see `rake -D`).
- Clean up ChefZero::Server default opts and move duplicated logic to `start_chef_server` method.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/run_oc_pedant.rb | 105 |
1 files changed, 73 insertions, 32 deletions
diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index 92ef136..c3d4e7f 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -5,6 +5,42 @@ require 'bundler/setup' require 'chef_zero/server' require 'rspec/core' +# This file runs oc-chef-pedant specs and is invoked by `rake pedant` +# and other Rake tasks. Run `rake -T` to list tasks. +# +# Options for oc-chef-pedant and rspec can be specified via +# ENV['PEDANT_OPTS'] and ENV['RSPEC_OPTS'], respectively. +# +# The log level can be specified via ENV['LOG_LEVEL']. +# +# Example: +# +# $ PEDANT_OPTS="--focus-users --skip-keys" \ +# > RSPEC_OPTS="--fail-fast --profile 5" \ +# > LOG_LEVEL=debug \ +# > rake pedant +# + +DEFAULT_SERVER_OPTIONS = { + port: 8889, + single_org: false, +}.freeze + +DEFAULT_LOG_LEVEL = :warn + +def log_level + return ENV['LOG_LEVEL'].downcase.to_sym if ENV['LOG_LEVEL'] + return :debug if ENV['DEBUG'] + DEFAULT_LOG_LEVEL +end + +def start_chef_server(opts={}) + opts = DEFAULT_SERVER_OPTIONS.merge(opts) + opts[:log_level] = log_level + + ChefZero::Server.new(opts).tap {|server| server.start_background } +end + def start_cheffs_server(chef_repo_path) require 'chef/version' require 'chef/config' @@ -34,37 +70,42 @@ def start_cheffs_server(chef_repo_path) data_store.set(%w(organizations pedant-testorg groups admins), '{ "users": [ "pivotal" ] }') data_store.set(%w(organizations pedant-testorg groups users), '{ "users": [ "pivotal" ] }') - server = ChefZero::Server.new( - port: 8889, - data_store: data_store, - single_org: false, - #log_level: :debug - ) - server.start_background - server + start_chef_server(data_store: data_store) +end + +def pedant_args_from_env + args_from_env('PEDANT_OPTS') end -tmpdir = nil +def rspec_args_from_env + args_from_env('RSPEC_OPTS') +end + +def args_from_env(key) + return [] unless ENV[key] + ENV[key].split +end begin - if ENV['FILE_STORE'] - require 'tmpdir' - require 'chef_zero/data_store/raw_file_store' - tmpdir = Dir.mktmpdir - data_store = ChefZero::DataStore::RawFileStore.new(tmpdir, true) - data_store = ChefZero::DataStore::DefaultFacade.new(data_store, false, false) - server = ChefZero::Server.new(:port => 8889, :single_org => false, :data_store => data_store) - server.start_background - - elsif ENV['CHEF_FS'] - require 'tmpdir' - tmpdir = Dir.mktmpdir - server = start_cheffs_server(tmpdir) + tmpdir = nil + server = + if ENV['FILE_STORE'] + require 'tmpdir' + require 'chef_zero/data_store/raw_file_store' + tmpdir = Dir.mktmpdir + data_store = ChefZero::DataStore::RawFileStore.new(tmpdir, true) + data_store = ChefZero::DataStore::DefaultFacade.new(data_store, false, false) + + start_chef_server(data_store: data_store) + + elsif ENV['CHEF_FS'] + require 'tmpdir' + tmpdir = Dir.mktmpdir + start_cheffs_server(tmpdir) - else - server = ChefZero::Server.new(:port => 8889, :single_org => false)#, :log_level => :debug) - server.start_background - end + else + start_chef_server + end require 'rspec/core' require 'pedant' @@ -83,6 +124,7 @@ begin '--skip-users', '--skip-organizations', '--skip-multiuser', + '--skip-user-keys', # chef-zero has some non-removable quirks, such as the fact that files # with 255-character names cannot be stored in local mode. This is @@ -104,7 +146,8 @@ begin # are turned off" - @jkeiser # # ...but we're not there yet - '--skip-keys', + '--skip-controls', + '--skip-acl', # Chef Zero does not intend to support validation the way erchef does. '--skip-validation', @@ -143,12 +186,10 @@ begin default_skips + chef_fs_skips + %w{ --skip-knife } end - Pedant.setup(pedant_args) - - fail_fast = %w()#--fail-fast) - #fail_fast = ["--fail-fast"] + Pedant.setup(pedant_args + pedant_args_from_env) - result = RSpec::Core::Runner.run(Pedant.config.rspec_args + fail_fast) + rspec_args = Pedant.config.rspec_args + rspec_args_from_env + result = RSpec::Core::Runner.run(rspec_args) server.stop if server.running? ensure |