summaryrefslogtreecommitdiff
path: root/spec/integration/indirector
AgeCommit message (Collapse)AuthorFilesLines
2014-07-24(maint) Remove unnecessary Puppet.settings.clear calls from specsJosh Partlow2-4/+0
I believe most of these predated our clearing the settings before each test in the central puppet/test/test_helper.rb. And since we then set some base settings (such as :environment_timeout) in the test_helper, the effect of a secondary clear in the test itself is to wipe out the baseline setup test_helper just laid down. In particular this is a problem with environment_timeout, as it leads to tests which end up creating environments, getting them cached with the default 180s timeout, which can leak to subsequent tests and create unpleasant spec order issues.
2014-06-26(PUP-2104) Add cfacter setting to enable cfacter implementation.Peter Huene1-1/+1
Adding a --cfacter setting that will replace the facter implementation with the native facter implementation if the following conditions are met: * cfacter is installed * the version of cfacter is at least 0.2.0 (not yet released). * facter has not evaluated any facts by the time the setting is set. To accomplish this last point, certain default setting values needed to be delay-evaluated as they relied on facts. Therefore a :default for a setting now accepts a Proc and calls the Proc only once when the default value is needed.
2014-05-16(PUP-2519) Create fallback environment only for default productionJosh Partlow1-2/+2
The goal here was to only produce a fallback environment for the default 'production' environment which would only be found if the production directory environment did not exist. All other cases would raise an error during application start up if the environment did not exist. Except for applications in agent mode which currently need the concept of the environment they will be requesting, but should not have to create or verify the existence of a locally matching environment in their environmentpath. A few other changes are made to further narrow the scope of code making open requests for the configured environment: * indirection request - looks up current environment now, relying on this having been set by whatever application is making the request. * puppet apply - instead of creating a new loader with a single static environment, it overrides current_environment instead. * puppet util commandline - does not attempt to look for additional plugins if there is no environment to search in. It relies on application to raise an error instead, if necessary.
2014-04-28(PUP-1699) Tie resource environment to catalogAndrew Parker2-2/+2
Previously resources would end up "floating away" from the catalog that contained them because they wouldn't use the catalog as their source for an environment. This also extended to catalogs, which lost track of their environment at times. So in order to have resources use the environment of their catalog, the catalog needed to have a guaranteed environment. This adds an environment parameter to the catalog constructor and uses it to drive the environment to use for everything in that catalog. The resource now uses its catalog's environment, if it has a catalog, or it uses the new NONE environment, if it does not have a catalog. When catalogs are deserialized, they also need to have a reference to *some* environment. However, since they only have a name of the environment, there isn't any guarantee that an environment of that name is available locally. To deal with this there is a new "remote" environment constructor to be able to create references to the remote environment of the catalog. This is used as the environment of a deserialized catalog. We (Joshua Partlow and Andrew Parker) tried to have the environment a required parameter of catalog construction, but it appears that creating catalogs is public API and so cannot be changed (we verified this by checking stdlib tests).
2014-04-07(PUP-2158) Default a missing manifest to no_manifestAndrew Parker1-1/+1
The tests were often creating environments that didn't need to have manifests. Since we didn't have a way of specifying that when they were written, we used '' to fill in the blank. This actually caused a large number of tests to try to find code to load in the PWD, which caused tests to break if a developer had parse errors in manifests being used for testing in the root directory of their puppet project. This changes the manifest to be optional and removes '' from those tests. The tests no longer fail if a bad manifest is in the PWD :D
2014-03-21(maint) Check for files by full nameAndrew Parker1-23/+20
Periodically this test would fail with a message about some path being a directory. It turns out that what was happening was that that generated name for the temp directory would end in "one" or "two". This caused the test to detect the directory entry in the response from the search request to be one of the files and so it would try to read the contents, which wasn't possible because it was the directory. This changes it to check for the files by the full path and use "include_in_any_order" to pull together two tests into one.
2014-01-29(PUP-1118) Stop using Environment.newAndrew Parker1-3/+2
Instead of creating environments directly, we need to go through the configured environment loaders, otherwise environments can't come from other places.
2014-01-06(PUP-716) Change Puppet::FileSystem::File to module methodsHenrik Lindberg2-3/+3
This changes the API in a new implementation in a file called file_.rb The intent is that it should replace the implemntation in File, or perhaps directly in a Puppet::FileSystem class.
2013-11-08(#19447) Puppet::FileSystem::File.exist?Ethan J. Brown2-3/+3
- All previous File and FileTest calls to exist? or exists? go through the new FileSystem::File abstraction so that the implementation can later be swapped for a Windows specific one to support symlinks
2013-10-23(Maint) Convert uses of IO.binread to P::FS::FileAndrew Parker1-4/+2
Now that we have Puppet::FileSystem::File we can start using it in more places and start getting rid of some of the monkey patches that puppet has been doing.
2013-10-11(#19514) Fix up tests that were not providing a valid NodeAndrew Parker1-13/+16
Several of the tests were not providing a valid Puppet::Node object when they called the compiler. They were either providing nil, or a mock. This resulted in invalid calls and failing tests when the internals of the compiler were changed. Instead of changing the internals of the compiler for this invalid way of being called, this changes the tests and makes the compiler assume that it is working with good parameters.
2013-02-28(#19392) (CVE-2013-1653) Validate instances passed to indirectorPatrick Carlisle1-1/+1
This adds a general validation method to check that only valid instances can be passed into the indirector. Since access control is based on the URI but many operations directly use the serialized instance passed in, it was possible to bypass restrictions by passing in a custom object. Specifically it was possible to cause the puppet kick indirection to execute arbitrary code by passing in an instance of the wrong class. This validates that the instance is of the correct type and that the name matches the key that was used to authorize the request.
2012-10-26(#7622) Deprecate and remove features.pson?Andrew Parker1-1/+1
PSON is always available and so the pson feature was only used for the side-effect of requiring the pson files. This commit deprecates the pson feature and moves the requires to the puppet.rb file so that PSON is available early on.
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune7-7/+7
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-08-16Test that facts preserve casePatrick Carlisle1-0/+22
2012-07-02(maint) Standardize on /usr/bin/env ruby -S rspecJeff McCune6-6/+6
Without this patch some spec files are using `ruby -S rspec` and others are using `rspec`. We should standardize on a single form of the interpreter used for spec files. `ruby -S rspec` is the best choice because it correctly informs editors such as Vim with Syntastic that the file is a Ruby file rather than an Rspec file.
2012-04-23Make positional arguments distinct in Request#initializePatrick Carlisle2-4/+4
Puppet::Indirector::Request#initialize had a weird implementation giving variable semantics to positional arguments. This makes it normal again.
2012-04-18Use conditional pending to block out "fails_on_windows" tests.Daniel Pittman1-8/+12
A whole bunch of tests scattered through the system fail on Windows, around features that are not supported on that platform. (They are things that only the master does, which an agent-only platform doesn't need to support.) These were tagged `fails_on_windows` to allow filtering them from rspec runs, which is great, but doesn't actually communicate nearly as much useful information as it would if we used the "conditionally pending" facilities that rspec has supported since 2.3. That gives us two key things: one, it works automatically based on our knowledge of the platform, which means you can't forget to turn off failing tests. Two, it means that if the test starts unexpectedly passing we also get a failure, since we should respond to "works when it shouldn't" as seriously as "fails when it shouldn't". Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-01-23(#11955) Refactor to use IO.binreadJosh Cooper1-1/+1
Previously, I had created a utility method `Puppet::Util.binread`, since `IO.binread` was added in ruby 1.9. This commit monkey patches the method, if it's not defined, to make the transition to ruby 1.9 seamless. And while I was at it, I add the corresponding `IO.binwrite` method. The motivation for these methods is that, in general, we should always be using binary mode when performing file I/O. However, text mode is the default on Windows, and using text mode can corrupt binary data, e.g. executables. So use binary mode, unless you know what text mode is and why you need to use it. Conflicts: spec/unit/file_serving/content_spec.rb
2012-01-18(#11996) Fix file content test after hash changes.Daniel Pittman1-2/+2
CVE-2011-4815 changed the order that hashes returned their content; that, in turn, changed the order that directory entries were returned to something much more likely to be random. This broke the test that assumed the order of '.' and 'file.rb' would be consistent; this fixes that by finding the right entry in the result instead of assuming it is always in the same slot. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-01-12(#11929) Always serve files in binary modeJosh Cooper2-7/+7
Previously, Windows agents were reading files in text mode when serving them locally, such as when serving files from a local module, corrupting binary files in the process. This commit reads files in binary mode, which is a noop on Unix. Serving files from remote puppet masters was fixed in #9983.
2011-10-05Change test to not call 'rm -rf'Josh Cooper1-15/+9
Previously the test was failing on Windows because there were problems with local file serving on Windows. That part was fixed, so the only remaining issue was changing the test to not call 'rm -rf'. This commit converts the tests to the new style, using tmpfile, etc. and removes the fails_on_windows tag.
2011-10-03Remove 'fails_on_windows' tag for passing testsJosh Cooper2-2/+2
Many tests were previously tagged as 'fails_on_windows' and excluded from Jenkins, because we did not have user, group, etc providers on Windows. Now that these providers have been implemented, these tests have been re-enabled (by removing the rspec exclude filter).
2011-08-19Remove use of Util::Cacher in FileServing::ConfigurationNick Lewis1-1/+1
This class was using Util::Cacher for its singleton instance, when that was unnecessary. The FileServing::Configuration instance already manages whether or not to reparse its config file, based on whether it has changed. Thus, there is no need for it to be manually expired via the cacher. Reviewed-By: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 4bad729f56c26d8154cd0f20614fa4e478de9d40)
2011-08-19Maint: Tagged spec tests that are known to fail on WindowsJosh Cooper3-3/+3
Many spec tests fail on Windows because there are no default providers implemented for Windows yet. Several others are failing due to Puppet::Util::Cacher not working correctly, so for now the tests that are known to fail are marked with :fails_on_windows => true. To skip these tests, you can run: rspec --tag ~fails_on_windows spec Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 255c5b4663bd389d2c87a2d39ec350034421a6f0) Conflicts: spec/unit/resource/catalog_spec.rb
2011-08-19Fix tests with "relative" paths on WindowsJosh Cooper1-2/+4
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows, which breaks many test cases. This commit adds a method to PuppetSpec::Files.make_absolute that makes the path absolute in test cases. On Unix (Puppet.features.posix?) it is a no-op. On Windows, (Puppet.features.microsoft_windows?) the drive from the current working directory is prepended. Reviewed-by: Jacob Helwig <jacob@puppetlabs.com> (cherry picked from commit 462a95e3d077b1915a919399b846068816c84583) Conflicts: spec/unit/parser/functions/extlookup_spec.rb
2011-08-18maint: remove inaccurate copyright and license statements.Daniel Pittman3-12/+0
For a while Luke, and other authors, injected a created tag, copyright statement, and "All rights reserved" into every new file they added to the Puppet project. This isn't really true, and we have a global license covering the code, so we have now stripped out all those old tags. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2011-04-19Fixed #7166 - Replaced deprecated stomp "send" method with "publish"James Turnbull1-2/+2
The "send" method in the stomp gem has been deprecated since: http://gitorious.org/stomp/mainline/commit/d542a976028cb4c5badcbb69e3383e746721e44c It's been replaced with the "publish" method. Also renamed the send_message method to publish_message more in keeping with language used in queuing.
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman6-9/+6
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman6-6/+6
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2011-03-31(6911) Refactor to localize eval_generate dependency assumptionsMarkus Roberts1-5/+2
To implement #6911 we will need to be able to make incremental descisions about order of application based only on the contents of the resource graph and local "working data." This commit begins to pull the needed structure into a method (visit_resources) while, for the moment, maintaining the original semantic. Paired-with: Jesse Wolfe
2011-03-22maint: Change code for finding spec_helper to work with Ruby 1.9Matt Robinson2-2/+2
Running the specs under Ruby 1.9 didn't work using the lambda to recurse down directories to find the spec_helper. Standardizing the way to find spec_helper like the rest of specs seemed like the way to go. Here's the command line perl I used to make the change: perl -p -i -e "s/Dir.chdir.*lambda.*spec_helper.*$/require File.expand_path(File.dirname(__FILE__) + '\/..\/..\/spec_helper')/" `find spec -name "*_spec.rb"` Then I fixed the number of dots for files that weren't two levels from the spec dir and whose tests failed. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
2011-01-06Merge branch '2.6.x' into nextNick Lewis1-4/+1
Conflicts: Rakefile lib/puppet/resource/type_collection.rb lib/puppet/simple_graph.rb lib/puppet/transaction.rb lib/puppet/transaction/report.rb lib/puppet/util/metric.rb spec/integration/indirector/report/rest_spec.rb spec/spec_specs/runnable_spec.rb spec/unit/configurer_spec.rb spec/unit/indirector_spec.rb spec/unit/transaction/change_spec.rb
2011-01-04(#5771) Upgrade rspec to version 2Matt Robinson1-4/+1
The biggest change is that we no longer need to monkey patch rspec to get confine behavior. Describe blocks can now be conditional like confine used to be. "describe" blocks with "shared => true" are now "shared_examples_for". Paired-With: Nick Lewis
2010-12-30(#5715) Changed the type of metric names to always be strings.Paul Berry1-16/+12
2010-12-16(#5493) Add report_format, puppet_version, and configuration_version to ReportsNick Lewis1-1/+1
Current report formats are: 0: 0.25 reports and earlier 1: 0.26.1 - 0.26.4 reports 2: 0.26.5 and beyond Paired-With: Jesse Wolfe
2010-12-06maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson4-4/+4
Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
2010-11-29Maint: Refactor tests to use <class>.indirection.<method>Paul Berry3-7/+7
Replaced uses of the find, search, destroy, and expire methods on model classes with direct calls to the indirection objects. This change affects tests only.
2010-11-16[#5322] (#5322) Remove spec file that adds little value and causes failuresMatt Robinson1-533/+0
spec/integration/indirector/rest_spec.rb has been deleted in puppet’s next branch because it was found that the things being tested were already covered in spec/unit/network/http/*. Also, the tests being deleted were so overly mocked they weren’t testing much, and firing up webrick as part of the tests was slow and causes intermittent failures on Hudson. This was discussed on the dev mailing list in the really long thread "No puppet developer patches to the puppet-dev list". Reviewed-by: Jesse Wolfe <jesse@puppetlabs.com>
2010-11-13Fix #5289 -- Bad copy/paste changes message on test failureMarkus Roberts3-3/+5
In my fix for #4894 (commit a097b939ab52bafb681cf7c5dcaf11717add07e6) I made and tested the fix in one case and then copied most of it (all but a variable initialization, Doh!) to two other locations. This caused tests that would have failed with a socket-in-use error to fail with a different error rather than retrying. Also fixed the spelling of "simultaneous."
2010-11-12Fix for #4894 -- retry tests if port is in useMarkus Roberts3-6/+28
If multiple processes are running the spec tests they may conflict trying to listen on a port. If this happens the test waits 0.1 seconds and retries for up to 100 times before marking the test pending due to too many conflicts.
2010-11-02Maint: Remove Indirector::Request objects from HTTP Handler and API V1Jesse Wolfe6-934/+0
This is a maintenance refactor to reduce the dependencies between the rest API and the implementation of the Indirector. The HTTP Handler code was creating temporary Request objects that were not actually being passed to the Indirector.
2010-10-28[#4894] Randomize port on webrick testsMatt Robinson2-7/+15
This isn't a great test fix, but it should be enough for now to stop the sporadic test failures in Hudson where webrick isn't releasing it's port which causes other tests to fail. I created ticket #5098 as a reminder to refactor these tests later. Reviewed-by: Paul Berry
2010-08-03[#4284] Fix failing specs run as root due to missing puppet groupNick Lewis6-0/+6
These specs 'use' some settings which create directories belonging to the 'service' user/group. If the default service group doesn't exist, these fail. This patch explicitly sets the service group to the gid of the process, which is known to be accessible by the user.
2010-07-09Code smell: Two space indentationMarkus Roberts12-1040/+1040
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
2010-07-09Code smell: Avoid needless decorationsMarkus Roberts1-1/+1
* Replaced 704 occurances of (.*)\b([a-z_]+)\(\) with \1\2 3 Examples: The code: ctx = OpenSSL::SSL::SSLContext.new() becomes: ctx = OpenSSL::SSL::SSLContext.new The code: skip() becomes: skip The code: path = tempfile() becomes: path = tempfile * Replaced 31 occurances of ^( *)end *#.* with \1end 3 Examples: The code: becomes: The code: end # Dir.foreach becomes: end The code: end # def becomes: end
2010-07-09Code smell: Use string interpolationMarkus Roberts1-3/+3
* Replaced 83 occurances of (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[]) with \1#{\2}" 3 Examples: The code: puts "PUPPET " + status + ": " + process + ", " + state becomes: puts "PUPPET " + status + ": " + process + ", #{state}" The code: puts "PUPPET " + status + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" The code: }.compact.join( "\n" ) + "\n" + t + "]\n" becomes: }.compact.join( "\n" ) + "\n#{t}" + "]\n" * Replaced 21 occurances of (.*)" *[+] *" with \1 3 Examples: The code: puts "PUPPET #{status}" + ": #{process}" + ", #{state}" becomes: puts "PUPPET #{status}" + ": #{process}, #{state}" The code: puts "PUPPET #{status}" + ": #{process}, #{state}" becomes: puts "PUPPET #{status}: #{process}, #{state}" The code: res = self.class.name + ": #{@name}" + "\n" becomes: res = self.class.name + ": #{@name}\n" * Don't use string concatenation to split lines unless they would be very long. Replaced 11 occurances of (.*)(['"]) *[+] *(['"])(.*) with 3 Examples: The code: o.define_head "The check_puppet Nagios plug-in checks that specified " + "Puppet process is running and the state file is no " + becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + The code: o.separator "Mandatory arguments to long options are mandatory for " + "short options too." becomes: o.separator "Mandatory arguments to long options are mandatory for short options too." The code: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " + "older than specified interval." becomes: o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval." * Replaced no occurances of do (.*?) end with {\1} * Replaced 1488 occurances of "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b) with 20 Examples: The code: args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",") becomes: args[0].split(/\./).map do |s| "dc=#{s}" end.join(",") The code: puts "%s" % Puppet.version becomes: puts "#{Puppet.version}" The code: raise "Could not find information for %s" % node becomes: raise "Could not find information for #{node}" The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file" The code: Puppet.err "Could not run %s: %s" % [client_class, detail] becomes: Puppet.err "Could not run #{client_class}: #{detail}" The code: raise "Could not find handler for %s" % arg becomes: raise "Could not find handler for #{arg}" The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" The code: raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail becomes: raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}" The code: raise "Could not find facts for %s" % Puppet[:certname] becomes: raise "Could not find facts for #{Puppet[:certname]}" The code: raise ArgumentError, "%s is not readable" % path becomes: raise ArgumentError, "#{path} is not readable" The code: raise ArgumentError, "Invalid handler %s" % name becomes: raise ArgumentError, "Invalid handler #{name}" The code: debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str] becomes: debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'" The code: raise Puppet::Error, "unknown cert type '%s'" % hash[:type] becomes: raise Puppet::Error, "unknown cert type '#{hash[:type]}'" The code: Puppet.info "Creating a new certificate request for %s" % Puppet[:certname] becomes: Puppet.info "Creating a new certificate request for #{Puppet[:certname]}" The code: "Cannot create alias %s: object already exists" % [name] becomes: "Cannot create alias #{name}: object already exists" The code: return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum] becomes: return "replacing from source #{metadata.source} with contents #{metadata.checksum}" The code: it "should have a %s parameter" % param do becomes: it "should have a #{param} parameter" do The code: describe "when registring '%s' messages" % log do becomes: describe "when registring '#{log}' messages" do The code: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l } becomes: paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" } The code: assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do becomes: assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
2010-07-09Code smell: Inconsistent indentation and related formatting issuesMarkus Roberts1-1/+4
* Replaced 163 occurances of defined\? +([@a-zA-Z_.0-9?=]+) with defined?(\1) This makes detecting subsequent patterns easier. 3 Examples: The code: if ! defined? @parse_config becomes: if ! defined?(@parse_config) The code: return @option_parser if defined? @option_parser becomes: return @option_parser if defined?(@option_parser) The code: if defined? @local and @local becomes: if defined?(@local) and @local * Eliminate trailing spaces. Replaced 428 occurances of ^(.*?) +$ with \1 1 file was skipped. test/ral/providers/host/parsed.rb because 0 * Replace leading tabs with an appropriate number of spaces. Replaced 306 occurances of ^(\t+)(.*) with Tabs are not consistently expanded in all environments. * Don't arbitrarily wrap on sprintf (%) operator. Replaced 143 occurances of (.*['"] *%) +(.*) with Splitting the line does nothing to aid clarity and hinders further refactorings. 3 Examples: The code: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] becomes: raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)] The code: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] becomes: Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig] The code: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] becomes: $stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus] * Don't break short arrays/parameter list in two. Replaced 228 occurances of (.*) +(.*) with 3 Examples: The code: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) becomes: puts @format.wrap(type.provider(prov).doc, :indent => 4, :scrub => true) The code: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) becomes: assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type) The code: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") becomes: assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk") * If arguments must wrap, treat them all equally Replaced 510 occurances of lines ending in things like ...(foo, or ...(bar(1,3), with \1 \2 3 Examples: The code: midscope.to_hash(false), becomes: assert_equal( The code: botscope.to_hash(true), becomes: # bottomscope, then checking that we see the right stuff. The code: :path => link, becomes: * Replaced 4516 occurances of ^( *)(.*) with The present code base is supposed to use four-space indentation. In some places we failed to maintain that standard. These should be fixed regardless of the 2 vs. 4 space question. 15 Examples: The code: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc becomes: def run_comp(cmd) puts cmd results = [] old_sync = $stdout.sync $stdout.sync = true line = [] begin open("| #{cmd}", "r") do |f| until f.eof? do c = f.getc The code: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( becomes: s.gsub!(/.{4}/n, '\\\\u\&') } string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&] } string.gsub!(/( The code: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } becomes: end } rvalues: rvalue | rvalues comma rvalue { if val[0].instance_of?(AST::ASTArray) result = val[0].push(val[2]) else result = ast AST::ASTArray, :children => [val[0],val[2]] end } The code: #passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } becomes: # passwdproc = proc { @password } keytext = @key.export( OpenSSL::Cipher::DES.new(:EDE3, :CBC), @password ) File.open(@keyfile, "w", 0400) { |f| f << keytext } The code: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") becomes: end def to_manifest "%s { '%s':\n%s\n}" % [self.type.to_s, self.name, @params.collect { |p, v| if v.is_a? Array " #{p} => [\'#{v.join("','")}\']" else " #{p} => \'#{v}\'" end }.join(",\n") The code: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", becomes: via the augeas tool. Requires: - augeas to be installed (http://www.augeas.net) - ruby-augeas bindings Sample usage with a string:: augeas{\"test1\" : context => \"/files/etc/sysconfig/firstboot\", changes => \"set RUN_FIRSTBOOT YES\", The code: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do becomes: names.should_not be_include("root") end describe "when generating a purgeable resource" do it "should be included in the generated resources" do Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource] @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref) end end describe "when the instance's do not have an ensure property" do The code: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') becomes: describe "when the instance's do not have an ensure property" do it "should not be included in the generated resources" do @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo') Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource] @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref) end end describe "when the instance's ensure property does not accept absent" do it "should not be included in the generated resources" do @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar') The code: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) becomes: func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( :name => "template", :ftype => :rvalue, :arguments => AST::ASTArray.new( :children => [stringobj(template)] ) The code: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") becomes: assert( @store.allowed?("hostname.madstop.com", "192.168.1.50"), "hostname not allowed") assert( ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"), "subname name allowed") The code: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } becomes: assert_nothing_raised { server = Puppet::Network::Handler.fileserver.new( :Local => true, :Config => false ) } The code: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid becomes: 'yay', { :failonfail => false, :uid => @user.uid, :gid => @user.gid } ).returns('output') output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid The code: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' becomes: ).times(1) pkg.provider.expects( :aptget ).with( '-y', '-q', 'remove', 'faff' The code: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs becomes: johnny one two billy three four\n" # Just parse and generate, to make sure it's isomorphic. assert_nothing_raised do assert_equal(text, @parser.to_file(@parser.parse(text)), "parsing was not isomorphic") end end def test_valid_attrs The code: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element| becomes: "testing", :onboolean => [true, "An on bool"], :string => ["a string", "A string arg"] ) result = [] should = [] assert_nothing_raised("Add args failed") do @config.addargs(result) end @config.each do |name, element|
2010-06-28[#3994-part 2] rename integration tests to *_spec.rbMarkus Roberts12-0/+0
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
2010-06-21[#1621] Composite keys for resourcesJesse Wolfe1-6/+6
This patch implements the fundamental pieces of the move to composite keys: * Instead of having a single namevar, we have a non-empty collection of them, and two resources are the same if and only if all of them match. Note that the present situation is a special case of this, where the collection always has exactly one member. * As currently, namevar is determined by the type. * Instead just of inferring the single namevar from the title we let types decompose the title into values for several (perhaps all) of the namevar components; note that the present situation is again a special case of this. Signed-off-by: Jesse Wolfe <jes5199@gmail.com>