diff options
author | Thom May <thom@chef.io> | 2016-07-29 17:00:49 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-07-29 17:00:49 +0100 |
commit | e257f450c044616fefbd15e9a180387aaaa572a1 (patch) | |
tree | 6a148967013485078af6601546bdb7b61c623f3c /spec | |
parent | 4c86d798010b73c76c916e601ff48c24ffb65dd6 (diff) | |
download | chef-zero-e257f450c044616fefbd15e9a180387aaaa572a1.tar.gz |
ChefStyletm/style
Signed-off-by: Thom May <thom@may.lt>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/run_oc_pedant.rb | 116 | ||||
-rw-r--r-- | spec/search_spec.rb | 22 | ||||
-rw-r--r-- | spec/server_spec.rb | 70 | ||||
-rw-r--r-- | spec/socketless_server_map_spec.rb | 4 | ||||
-rw-r--r-- | spec/support/oc_pedant.rb | 41 |
5 files changed, 125 insertions, 128 deletions
diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index 9c95b07..0347fbc 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -1,9 +1,9 @@ #!/usr/bin/env ruby -require 'bundler' -require 'bundler/setup' +require "bundler" +require "bundler/setup" -require 'chef_zero/server' -require 'rspec/core' +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. @@ -29,56 +29,56 @@ DEFAULT_SERVER_OPTIONS = { DEFAULT_LOG_LEVEL = :warn def log_level - return ENV['LOG_LEVEL'].downcase.to_sym if ENV['LOG_LEVEL'] - return :debug if ENV['DEBUG'] + 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={}) +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 } + ChefZero::Server.new(opts).tap { |server| server.start_background } end def start_cheffs_server(chef_repo_path) - require 'chef/version' - require 'chef/config' - require 'chef/chef_fs/config' - require 'chef/chef_fs/chef_fs_data_store' - require 'chef_zero/server' + require "chef/version" + require "chef/config" + require "chef/chef_fs/config" + require "chef/chef_fs/chef_fs_data_store" + require "chef_zero/server" Dir.mkdir(chef_repo_path) if !File.exists?(chef_repo_path) # 11.6 and below had a bug where it couldn't create the repo children automatically if Chef::VERSION.to_f < 11.8 - %w(clients cookbooks data_bags environments nodes roles users).each do |child| + %w{clients cookbooks data_bags environments nodes roles users}.each do |child| Dir.mkdir("#{chef_repo_path}/#{child}") if !File.exists?("#{chef_repo_path}/#{child}") end end # Start the new server - Chef::Config.repo_mode = 'hosted_everything' + Chef::Config.repo_mode = "hosted_everything" Chef::Config.chef_repo_path = chef_repo_path Chef::Config.versioned_cookbooks = true chef_fs_config = Chef::ChefFS::Config.new data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs_config.local_fs, chef_fs_config.chef_config) - data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, 'pedant-testorg') - data_store = ChefZero::DataStore::DefaultFacade.new(data_store, 'pedant-testorg', false) - data_store.create(%w(organizations pedant-testorg users), 'pivotal', '{}') - data_store.set(%w(organizations pedant-testorg groups admins), '{ "users": [ "pivotal" ] }') - data_store.set(%w(organizations pedant-testorg groups users), '{ "users": [ "pivotal" ] }') + data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, "pedant-testorg") + data_store = ChefZero::DataStore::DefaultFacade.new(data_store, "pedant-testorg", false) + data_store.create(%w{organizations pedant-testorg users}, "pivotal", "{}") + data_store.set(%w{organizations pedant-testorg groups admins}, '{ "users": [ "pivotal" ] }') + data_store.set(%w{organizations pedant-testorg groups users}, '{ "users": [ "pivotal" ] }') start_chef_server(data_store: data_store) end def pedant_args_from_env - args_from_env('PEDANT_OPTS') + args_from_env("PEDANT_OPTS") end def rspec_args_from_env - args_from_env('RSPEC_OPTS') + args_from_env("RSPEC_OPTS") end def args_from_env(key) @@ -89,17 +89,17 @@ end begin tmpdir = nil server = - if ENV['FILE_STORE'] - require 'tmpdir' - require 'chef_zero/data_store/raw_file_store' + 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' + elsif ENV["CHEF_FS"] + require "tmpdir" tmpdir = Dir.mktmpdir start_cheffs_server(tmpdir) @@ -107,42 +107,42 @@ begin start_chef_server end - require 'rspec/core' - require 'pedant' - require 'pedant/organization' + require "rspec/core" + require "pedant" + require "pedant/organization" # Pedant::Config.rerun = true - Pedant.config.suite = 'api' + Pedant.config.suite = "api" - Pedant.config[:config_file] = 'spec/support/oc_pedant.rb' + Pedant.config[:config_file] = "spec/support/oc_pedant.rb" # Because ChefFS can only ever have one user (pivotal), we can't do most of the # tests that involve multiple - chef_fs_skips = if ENV['CHEF_FS'] - [ '--skip-association', - '--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 - # reserved only for quirks that are *irrevocable* and by design; and - # should barely be used at all. - '--skip-chef-zero-quirks', - ] - else - [] - end + chef_fs_skips = if ENV["CHEF_FS"] + [ "--skip-association", + "--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 + # reserved only for quirks that are *irrevocable* and by design; and + # should barely be used at all. + "--skip-chef-zero-quirks", + ] + else + [] + end # The latest released Chef doesn't do ACLs, Cookbook Artifacts or Policies yet - chef_fs_skips << '--skip-acl' - chef_fs_skips << '--skip-cookbook-artifacts' - chef_fs_skips << '--skip-policies' + chef_fs_skips << "--skip-acl" + chef_fs_skips << "--skip-cookbook-artifacts" + chef_fs_skips << "--skip-policies" # Multi-keys don't work prior to 12.8 unless Gem::Requirement.new(">= 12.8.0").satisfied_by?(Gem::Version.new(Chef::VERSION)) - chef_fs_skips << '--skip-keys' + chef_fs_skips << "--skip-keys" end # These things aren't supported by Chef Zero in any mode of operation: @@ -153,30 +153,30 @@ begin # ...but we're not there yet # Chef Zero does not intend to support validation the way erchef does. - '--skip-validation', + "--skip-validation", # Chef Zero does not intend to support authentication the way erchef does. - '--skip-authentication', + "--skip-authentication", # Chef Zero does not intend to support authorization the way erchef does. - '--skip-authorization', + "--skip-authorization", # Omnibus tests depend on erchef features that are specific to erchef and # bundled in the omnibus package. Currently the only test in this category # is for the search reindexing script. - '--skip-omnibus', + "--skip-omnibus", # USAGs (user-specific association groups) are Authz groups that contain # only one user and represent that user's association with an org. Though # there are good reasons for them, they don't work well in practice and # only the manage console really uses them. Since Chef Zero + Manage is a # quite unusual configuration, we're ignoring them. - '--skip-usags', + "--skip-usags", # Chef 12 features not yet 100% supported by Chef Zero # The universe endpoint is unlikely to ever make sense for Chef Zero - '--skip-universe', + "--skip-universe", ] # The knife tests are very slow and don't give us a lot of extra coverage, diff --git a/spec/search_spec.rb b/spec/search_spec.rb index 54392a6..34ea5b9 100644 --- a/spec/search_spec.rb +++ b/spec/search_spec.rb @@ -1,11 +1,11 @@ -require 'chef_zero/solr/solr_parser' -require 'chef_zero/solr/solr_doc' +require "chef_zero/solr/solr_parser" +require "chef_zero/solr/solr_doc" describe ChefZero::Solr::SolrParser do let (:all_docs) do docs = [] - [{'foo' => 'a'}, - {'foo' => 'd'}].each_with_index do |h, i| + [{ "foo" => "a" }, + { "foo" => "d" }].each_with_index do |h, i| docs.push ChefZero::Solr::SolrDoc.new(h, i) end docs @@ -13,24 +13,24 @@ describe ChefZero::Solr::SolrParser do def search_for(query) q = ChefZero::Solr::SolrParser.new(query).parse - all_docs.select {|doc| q.matches_doc?(doc) } + all_docs.select { |doc| q.matches_doc?(doc) } end it "handles terms" do - search_for('foo:d').size.should eq(1) + search_for("foo:d").size.should eq(1) end it "handles ranges" do - search_for('foo:[a TO c]').size.should eq(1) + search_for("foo:[a TO c]").size.should eq(1) end it "handles -" do - search_for('-foo:a').size.should eq(1) + search_for("-foo:a").size.should eq(1) end it "handles wildcard ranges" do - search_for('foo:[* TO c]').size.should eq(1) - search_for('foo:[c TO *]').size.should eq(1) - search_for('foo:[* TO *]').size.should eq(2) + search_for("foo:[* TO c]").size.should eq(1) + search_for("foo:[c TO *]").size.should eq(1) + search_for("foo:[* TO *]").size.should eq(2) end end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 123a13e..64167e1 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -1,9 +1,9 @@ -require 'chef_zero/server' -require 'net/http' -require 'uri' +require "chef_zero/server" +require "net/http" +require "uri" describe ChefZero::Server do - context 'with a server bound to port 8889' do + context "with a server bound to port 8889" do before :each do @server = ChefZero::Server.new(:port => 8889) @server.start_background @@ -12,84 +12,84 @@ describe ChefZero::Server do @server.stop end - it 'a second server bound to port 8889 throws EADDRINUSE' do + it "a second server bound to port 8889 throws EADDRINUSE" do expect { ChefZero::Server.new(:port => 8889).start }.to raise_error Errno::EADDRINUSE end - it 'a server bound to range 8889-9999 binds to a port > 8889' do + it "a server bound to range 8889-9999 binds to a port > 8889" do server = ChefZero::Server.new(:port => 8889.upto(9999)) server.start_background expect(server.port).to be > 8889 expect(URI(server.url).port).to be > 8889 end - it 'a server bound to range 8889-8889 throws an exception' do + it "a server bound to range 8889-8889 throws an exception" do expect { ChefZero::Server.new(:port => 8889.upto(8889)).start_background }.to raise_error Errno::EADDRINUSE end - it 'has a very patient request timeout' do + it "has a very patient request timeout" do expect(@server.server.config[:RequestTimeout]).to eq 300 end - context 'accept headers' do + context "accept headers" do def get_nodes(accepts) uri = URI(@server.url) httpcall = Net::HTTP.new(uri.host, uri.port) - httpcall.get('/nodes', 'Accept' => accepts) + httpcall.get("/nodes", "Accept" => accepts) end def get_version uri = URI(@server.url) httpcall = Net::HTTP.new(uri.host, uri.port) - httpcall.get('/version', 'Accept' => 'text/plain, application/json') + httpcall.get("/version", "Accept" => "text/plain, application/json") end - it 'accepts requests with no accept header' do - request = Net::HTTP::Get.new('/nodes') - request.delete('Accept') + it "accepts requests with no accept header" do + request = Net::HTTP::Get.new("/nodes") + request.delete("Accept") uri = URI(@server.url) response = Net::HTTP.new(uri.host, uri.port).request(request) - expect(response.code).to eq '200' + expect(response.code).to eq "200" end - it 'accepts requests with accept: application/json' do - expect(get_nodes('application/json').code).to eq '200' + it "accepts requests with accept: application/json" do + expect(get_nodes("application/json").code).to eq "200" end - it 'accepts requests with accept: application/*' do - expect(get_nodes('application/*').code).to eq '200' + it "accepts requests with accept: application/*" do + expect(get_nodes("application/*").code).to eq "200" end - it 'accepts requests with accept: application/*' do - expect(get_nodes('*/*').code).to eq '200' + it "accepts requests with accept: application/*" do + expect(get_nodes("*/*").code).to eq "200" end - it 'denies requests with accept: application/blah' do - expect(get_nodes('application/blah').code).to eq '406' + it "denies requests with accept: application/blah" do + expect(get_nodes("application/blah").code).to eq "406" end - it 'denies requests with accept: blah/json' do - expect(get_nodes('blah/json').code).to eq '406' + it "denies requests with accept: blah/json" do + expect(get_nodes("blah/json").code).to eq "406" end - it 'denies requests with accept: blah/*' do - expect(get_nodes('blah/*').code).to eq '406' + it "denies requests with accept: blah/*" do + expect(get_nodes("blah/*").code).to eq "406" end - it 'denies requests with accept: blah/*' do - expect(get_nodes('blah/*').code).to eq '406' + it "denies requests with accept: blah/*" do + expect(get_nodes("blah/*").code).to eq "406" end - it 'denies requests with accept: <empty string>' do - expect(get_nodes('').code).to eq '406' + it "denies requests with accept: <empty string>" do + expect(get_nodes("").code).to eq "406" end - it 'accepts requests with accept: a/b;a=b;c=d, application/json;a=b, application/xml;a=b' do - expect(get_nodes('a/b;a=b;c=d, application/json;a=b, application/xml;a=b').code).to eq '200' + it "accepts requests with accept: a/b;a=b;c=d, application/json;a=b, application/xml;a=b" do + expect(get_nodes("a/b;a=b;c=d, application/json;a=b, application/xml;a=b").code).to eq "200" end - it 'accepts /version' do - expect(get_version.body.start_with?('chef-zero')).to be true + it "accepts /version" do + expect(get_version.body.start_with?("chef-zero")).to be true end end end diff --git a/spec/socketless_server_map_spec.rb b/spec/socketless_server_map_spec.rb index 0699b54..795dba4 100644 --- a/spec/socketless_server_map_spec.rb +++ b/spec/socketless_server_map_spec.rb @@ -1,5 +1,4 @@ -require 'chef_zero/socketless_server_map' - +require "chef_zero/socketless_server_map" describe "Socketless Mode" do @@ -72,5 +71,4 @@ describe "Socketless Mode" do end end - end diff --git a/spec/support/oc_pedant.rb b/spec/support/oc_pedant.rb index 6e39878..8d07f99 100644 --- a/spec/support/oc_pedant.rb +++ b/spec/support/oc_pedant.rb @@ -21,7 +21,7 @@ ################################################################################ # You MUST specify the address of the server the API requests will be # sent to. Only specify protocol, hostname, and port. -chef_server 'http://127.0.0.1:8889' +chef_server "http://127.0.0.1:8889" # If you are doing development testing, you can specify the address of # the Solr server. The presence of this parameter will enable tests @@ -54,7 +54,6 @@ search_server chef_server search_commit_url "/dummy" search_url_fmt "/dummy?fq=+X_CHEF_type_CHEF_X:%{type}&q=%{query}&wt=json" - # We're starting to break tests up into groups based on different # criteria. The proper API tests (the results of which are viewable # to OPC customers) should be the only ones run by Pedant embedded in @@ -69,10 +68,10 @@ search_url_fmt "/dummy?fq=+X_CHEF_type_CHEF_X:%{type}&q=%{query}&wt=json" # value. include_internal false -key = 'spec/support/stickywicket.pem' +key = "spec/support/stickywicket.pem" org(name: "pedant-testorg", - create_me: !ENV['CHEF_FS'], + create_me: !ENV["CHEF_FS"], validator_key: key) internal_account_url chef_server @@ -85,15 +84,15 @@ delete_org true # are using pre-existing users, you must supply a ':key_file' key, # which should be the fully-qualified path /on the machine Pedant is # running on/ to a private key for that user. -superuser_name 'pivotal' +superuser_name "pivotal" superuser_key key webui_key key def cheffs_or_else_user(value) - ENV['CHEF_FS'] ? "pivotal" : value + ENV["CHEF_FS"] ? "pivotal" : value end -keyfile_maybe = ENV['CHEF_FS'] ? { key_file: key } : { key_file: nil } +keyfile_maybe = ENV["CHEF_FS"] ? { key_file: key } : { key_file: nil } requestors({ :clients => { @@ -102,45 +101,45 @@ requestors({ :name => "pedant_admin_client", :create_me => true, :create_knife => true, - :admin => true + :admin => true, }, :non_admin => { - :name => 'pedant_client', + :name => "pedant_client", :create_me => true, :create_knife => true, }, :bad => { - :name => 'bad_client', + :name => "bad_client", :create_me => true, :create_knife => true, - :bogus => true - } + :bogus => true, + }, }, :users => { # An administrator in the testing organization :admin => { :name => cheffs_or_else_user("pedant_admin_user"), - :create_me => !ENV['CHEF_FS'], - :associate => !ENV['CHEF_FS'], - :create_knife => true + :create_me => !ENV["CHEF_FS"], + :associate => !ENV["CHEF_FS"], + :create_knife => true, }.merge(keyfile_maybe), :non_admin => { :name => cheffs_or_else_user("pedant_user"), - :create_me => !ENV['CHEF_FS'], - :associate => !ENV['CHEF_FS'], - :create_knife => true + :create_me => !ENV["CHEF_FS"], + :associate => !ENV["CHEF_FS"], + :create_knife => true, }.merge(keyfile_maybe), # A user that is not a member of the testing organization :bad => { :name => cheffs_or_else_user("pedant-nobody"), - :create_me => !ENV['CHEF_FS'], + :create_me => !ENV["CHEF_FS"], :create_knife => true, - :associate => false + :associate => false, }.merge(keyfile_maybe), - } + }, }) self[:tags] = [:validation, :authentication, :authorization] |