summaryrefslogtreecommitdiffstats
path: root/spec/lib
Commit message (Collapse)AuthorAgeFilesLines
* Consolidate test logic determining if a registered file is in the temp directoryJacob Helwig2011-08-021-10/+8
| | | | | | | | | | | | | | | | | | | | | | | Previously, we were always using string comparisons, and hard-coded paths to temp locations on non-Windows platforms. This was problematic for a few reasons. We had to maintain a list of temp locations for the various platforms, and the string comparisons were unreliable on Windows, since paths have two string representations (the "short" name containing a ~ followed by a number, and the "full" name). By getting the current temp location using Dir.tempdir (the same mechanism our temp creation code uses), we no longer need to maintain the list of temp locations. Also, rather than doing string comparisons on file paths, we can use a combination of Pathname#ascend, and File.identical? to determine if the path registered as a temp file for deletion was actually created in the temp location. With this refactoring, the same code now works for both Windows, and non-Windows platforms. Reviewed-by: Nick Lewis <nick@puppetlabs.com>
* Merge branch '2.7.x'Nick Lewis2011-07-253-0/+15
|\ | | | | | | | | | | Conflicts: lib/puppet/type/file/source.rb spec/unit/resource/catalog_spec.rb
| * maint: Fix Face testing bug 1.9.2 revealed.Daniel Pittman2011-07-252-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Ruby 1.8.7 is fairly lax about various bits of introspection, including that we can't tell much about what arguments a block takes. Ruby 1.9.2 makes it possible to do this, though. Meanwhile, the Faces system uses this to make sure that scripts and actions take the right set of arguments, to avoid surprises: failing early and explicitly is better than failing at runtime. Which, in final turn, exposes that I forgot to accept the right arguments in a couple of my testing actions for Faces, but didn't notice because 1.8.7 doesn't check that, and I didn't test on 1.9.2.
| * (#7184) Load the core of obsolete versions of Faces.Daniel Pittman2011-07-222-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | When we define an action on an older version of a Face, we must be sure to directly load the core of that version, not just define it with the external Action(s) that it had. Otherwise we break our contract, which is that any core Actions for a specific version will be available to your external Action for as long as we support that core version. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
| * (#7184) Find actions bound to other versions of Faces.Daniel Pittman2011-07-221-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When we first touch a Face, we load all the available Actions from disk. Given they define themselves against a specific version of a Face, they are automatically available tied to the correct version; this makes it trivially possible to locate those on demand and return them. Now, we have the ability to find and, consequently, invoke Actions on older versions of Faces. We don't load enough context, though: the older face will only have external Actions defined, not anything core. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
* | Fix tests with "relative" paths on WindowsJosh Cooper2011-07-191-0/+10
|/ | | | | | | | | | | | | 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>
* #7211: more helpful error messages in various cases.Daniel Pittman2011-05-311-0/+5
| | | | | | | | | | | | We were emitting a bunch of unhelpful failure messages, surrounding invalid actions and especially default actions interacting with the command-line. This cleans those up, to give a helpful, informative, and correct message in all cases. Notably, we no longer report that there is no "default" action when you specify an unknown action on a face. This change revealed some other weaknesses in our unit tests, now correctly, that result in slightly more robust code.
* (#7291) The 'script' version of actions needs options argumentMatt Robinson2011-05-162-2/+2
| | | | | | | | | | Ruby 1.9 is stricter about arity for for arguments passed as a block. A test case just hadn't been updated to take this into account for Face scripts (a simpler form of action), which isn't surprising since script isn't used anywhere in the code, which makes it a prime candidate for removal as far as I'm concerned, but apparently Luke wants it in there. Reviewed-by: Pieter van de Bruggen <pieter@puppetlabs.com>
* (#7329) Consistent naming for rendering formats and hooks.Daniel Pittman2011-05-031-0/+6
| | | | | | | | | | | | We refer to rendering formats pretty consistently as `json`, `yaml`, `s`, and so forth; unqualified names. On the other hand, we refer to the rendering hooks *mostly* as `to_*`, except the `:for_humans` and `:json` formats. Which is kind of confusing because of the internal inconsistency, and because it doesn't match the public name. Fix the code to resolve both, so the `to_*` format still works, but we mostly expect to use the `*` version, to match public expectation.
* (#7282) action without `when_invoked` should fail...Daniel Pittman2011-05-021-1/+1
| | | | | | | | | | | | | | We used to let actions be declared without the `when_invoked` block, which was usually a sign of either someone writing their method code direct in action declaration, or someone forgetting to add their code at all. This was just let silently by: the error only showed up when you finally tried to invoke the action, and a NoMethod error was raised by the face. ...except for our own testing. We took advantage of this a whole pile of times in there; fixing the original UI issue means fixing all those too. Reviewed-By: Nick Lewis <nick@puppetlabs.com>
* maint: add a 'print' matcher to rspec, to inspect std{out,err}Daniel Pittman2011-04-281-0/+87
| | | | | | | | | | | | You can now write expectations along the lines of: expect { ... }.to print /whatever/ This will do the expected thing, which is to require that we print something matching that regular expression during the block. The output itself is suppressed during operation of the matcher. Paired-With: Max Martin <max@puppetlabs.com>
* (#6962) Add integration tests on Face documentation.Daniel Pittman2011-04-273-0/+6
| | | | | | | | | | We now run all the faces, and their actions, as well as global help through the wringer in this test: this way we can be confident that we have, at least, the ability to generate the help without a user-visible failure. We also check that we have set copyright and license terms in our own faces. Theoretically this might fail if the end user has extra faces on LOAD_PATH, but my hope is that we won't hit that...
* (#7157) Return a non-zero exit code on face failure.Daniel Pittman2011-04-221-0/+30
| | | | | | | | When a face or action fails we should exit non-zero on the CLI to signal this to our caller. "Fails" is defined as "raises an exception"; we don't treat any return value as a significant failure. Reviewed-By: Jesse Wolf <jesse@puppetlabs.com>
* Merge remote-tracking branch ↵Daniel Pittman2011-04-211-2/+3
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | 'remotes/lak/tickets/next/7118-summaries_for_all_faces' into 2.7.x Fix conflicts due to version drift in: lib/puppet/face/certificate.rb lib/puppet/face/facts.rb lib/puppet/face/node.rb lib/puppet/face/secret_agent.rb spec/lib/puppet/face/basetest.rb spec/unit/face/help_spec.rb Reviewed-By: Markus Roberts <markus@puppetlabs.com>
| * (7118) Adding summaries for all facesLuke Kanies2011-04-141-1/+3
| | | | | | | | | | | | | | | | | | It's usually just a one-liner, but when I saw an obvious opportunity for longer docs, I've added a @longdocs variable that can be converted to longer forms when ready. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* | (#7183) Implement "invisible glob" version matching for facesDaniel Pittman2011-04-211-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "Invisible glob", or "prefix", version matching means that when you specify a version string to use you can specify as little as one version number out of the semantic versioning spec. Matching is done on the prefix; an omitted number is treated as "anything" in that slot, and we return the highest matching versioned face by that spec. For example, given the set of versions: 1.0.0, 1.0.1, 1.1.0, 1.1.1, 2.0.0 The following would be matched: input matched 1 1.1.1 1.0 1.0.1 1.0.1 1.0.1 1.0.2 fail - no match 1.1 1.1.1 1.1.1 1.1.1 1.2 fail - no match
* | Merge branch ↵Daniel Pittman2011-04-151-0/+1
|\ \ | | | | | | | | | 'feature/2.7.x/6978-face-and-action-options-should-have-hooks-for-various-actions' into 2.7.x
| * | (#6978) Add before and after decorators to actions from options.Daniel Pittman2011-04-151-0/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Options can now add before_action and after_action blocks; these are invoked before or after any action is invoked on the face. This allows these options to declare common behaviour and have it automatically applied to the actions invoked. Option hooks have no defined order of invocation: they will run in a completely random order. Where there are dependencies they should be on the value of the options hash passed to the invocation, not on side-effects of the other invocations. You are not able to influence the arguments, options, or calling of the action body in a before or after decorator. This is by design. The invocation passes to the hook: 1. The action object representing this action. 2. The arguments to the action, as an array. 3. The options for the action, as a hash. Paired-With: Max Martin <max@puppetlabs.com>
* / Adding json-specific matchersLuke Kanies2011-04-141-0/+111
|/ | | | | | | | | | | | | | | | | These make the JSON tests much easier to read and write. They're the first custom matchers that I can find, so they're breaking a bit of new ground, but the JSON tests were pretty hard to read and there was a lot of duplication, so it seemed worth it. Note that for some reason they're not working on Facts - it seems to get immediately turned into a full instance by the JSON parsing subsystem, and I've no idea why. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com> Signed-off-by: Luke Kanies <luke@puppetlabs.com>
* maint: clean up the spec test headers in bulk.Daniel Pittman2011-04-135-0/+0
| | | | | | | 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.
* (#7056) Use 'face' rather than 'faces' in the production code.Daniel Pittman2011-04-133-3/+3
| | | | | | | | | After some discussion we decided that most uses of the Puppet Face infrastructure were about single faces on their own, not about the collection, and so we were better referring to Puppet::Face[...] in code. This implements that by translating names and references in the Ruby code to the new, s-less, name.
* maint: avoid making temporary dirs during testing.Daniel Pittman2011-04-121-0/+1
| | | | | | | | We used to create temporary directories to have some support files on disk during testing of faces; we don't really need that most of the time, and this updates a test to reflect that reality. Reviewed-By: Matt Robinson <matt@puppetlabs.com>
* (#6962) Implement Face#summary support for the help face.Daniel Pittman2011-04-121-0/+1
| | | | | | | | We now use the summary information available in other faces as part of emitting a list our list of available subcommands. This is seldom used in faces, but enough emit the information to prove the concept. Reviewed-By: Matt Robinson <matt@puppetlabs.com>
* maint: use FileUtil to remove files, not execDaniel Pittman2011-04-081-23/+33
| | | | | | | | | We used to shell out to chmod and rm to clean up temporary files; this lead to the cleanup method here being one of the largest consumers of walltime. Replacing that with FileUtil calls is as, or more, secure, and performs sufficiently well that we can just delegate. Reviewed-By: Matt Robinson <matt@puppetlabs.com>
* Merge puppet-interfaces into puppet.Daniel Pittman2011-04-071-0/+4
| | | | | This joins the two repositories, including full history, into a single run, as well as landing the interfaces work on the next branch ready for release.
* Merge branch '2.6.next' into nextMax Martin2011-03-231-0/+9
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 2.6.next: Fixed #6562 - Minor kick documentation fix (#6658) Propagate ENC connection errors to the agent (#4884) Remove typo from spec test (#4884) Modify tests to pass on non-OS X systems (#4884) Revise new exec tests, add a few more (#4884) Add an shell provider for execs (#4884) Fix Test::Unit exec tests (#4884) Break the exec type out to have a posix provider (#4884) Add consistent path validation and behavior (#4884) Add expand_path to requiring the spec_helper (#4884) Autorequire shared behaviors and method to silence warnings (#4884) Fix whitespace (#4884) Get rid of open3 require since it wasn't being used (#5814) Improved cron type specs (#5814) cron_spec shouldn't depend on cron provider Manually Resolved Conflicts: lib/puppet/util/command_line/puppetrun spec/spec_helper.rb spec/unit/type/exec_spec.rb spec/unit/type_spec.rb test/ral/type/exec.rb
| * (#4884) Autorequire shared behaviors and method to silence warningsDaniel Pittman2011-03-151-0/+9
| | | | | | | | | | | | | | with_verbose_disabled allows you to run tests that muck with constans without getting spammy warnings. Reviewed-by: Max Martin and Matt Robinson
* | (#6582) Don't demand the checkout be named 'puppet'.Daniel Pittman2011-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | As part of implementing the fixture support I hard-coded the assumption that the git checkout was a directory named 'puppet'; this broke on our CI server, and would break for anyone else who didn't follow that default. This commit eliminates that assumption and depends only on the appropriate part of the input filename. Reviewed-By: Paul Berry <paul@puppetlabs.com>
* | (#6582) move more helper code into methods, out of RSpec#configureDaniel Pittman2011-03-031-0/+23
| | | | | | | | | | | | | | | | We move the tempfile cleanup support off into the module that uses it, which removes some of the dependency on magic globals from configure. It still exists, but is hidden in the same module that uses it, which helps. Reviewed-By: Nick Lewis <nick@puppetlabs.com>
* | (#6582) add fixture helper methods to replace unit test code.Daniel Pittman2011-03-031-0/+28
|/ | | | | | | | | | | | | We validate that fixtures exist, when requested, or that they match something when they use a glob. This catches internal errors where we don't match any fixtures with a glob; this can reveal problems that would otherwise avoid all assertions and result in internal failures. The code is hidden out in a module, included in the main RSpec namespace. This doesn't clean up the API any, but it isolates the code more effectively and keeps the configuration file cleaner. Reviewed-By: Nick Lewis <nick@puppetlabs.com>
* [#4771] Import of manifests with the same name only happens oncePaul Berry2010-09-231-0/+1
| | | | | | | | | | | | | | | The function import_if_possible, which was supposed to be responsible for making sure that no two threads tried to import the same file at the same time, was not making this decision based on the full pathname of the file, since it was being invoked before pathnames were resolved. As a result, if we attempted to import two distinct files with the same name at the same time (either in two threads or in a single thread due to recursion), one of the files would not always get imported. Fixed this problem by moving the thread-safety logic to happen after filenames are resolved to absolute paths. This made it possible to simplify the thread-safety logic significantly.
* Code smell: Two space indentationMarkus Roberts2010-07-091-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Adding tmpfile cleanup to testsLuke Kanies2010-02-171-0/+10
| | | | Signed-off-by: Luke Kanies <luke@reductivelabs.com>
* Adding a Spec lib directory and moving tmpfile to itLuke Kanies2009-05-261-0/+9
| | | | | | | | | | | | | | We had a common pattern for creating a temporary file during integration tests, and this just makes that common pattern explicit by moving it to a module in the newly-created lib directory in the spec directory. We definitely don't want to go overboard in using libraries in our tests, but sometimes it gets a bit excessive to completely avoid them. Signed-off-by: Luke Kanies <luke@madstop.com>
* Moving $PUPPET/spec/lib/autotest up to $PUPPET/autotest as something has ↵Rick Bradley2007-12-0581-6087/+0
| | | | | | | | | | | | changed and it can't be found otherwise. Adding $PUPPET/vendor/gems, with unpacked rspec gem there, introducing to spec_helper.rb LOAD_PATH incantation. Eliminating ad hoc unpacked rspec from spec/lib. Moving monkey_patches and shared_behaviors up under spec/. Adjusting spec_helper.rb accordingly. Nuking spec/lib. Fixing up autotest/puppet_rspec.rb to be able to hunt down our vendor/gems/rspec/bin/spec binary. We can now run rspec without having to have the rspec gem installed.
* moving autotest directory to make it possible to run autotest againRick Bradley2007-12-053-150/+0
|
* Fixing #920 -- I have replaced the existing mount test with anLuke Kanies2007-11-261-4/+5
| | | | | rspec version. It's not perfect, in that it only tests the :ensure state, but that's where 90% of the behaviour is.
* Fixing the last failing test relating to the environment changesLuke Kanies2007-11-201-1/+2
|
* This won't be perfect by any stretch, but put in a moderately reasonable ↵Rick Bradley2007-10-261-0/+33
| | | | autotest config file.
* One significant step closer to getting autotest running properly on the ↵Rick Bradley2007-10-266-5/+147
| | | | | | | | | | | | | | | | | | | | Puppet specs. Created a spec/lib/monkey_patches/ directory for holding patches to RSpec functionality. Extraced 'confine' and 'runnable?' support from the local copy of RSpec (spec/lib/spec/) and now load them from the monkey_patches/ directory. Fixed a bad include in one of the specs. Made it possible for the gem-installed spec binary (which autotest calls) to be used with Puppet. Imported the Autotest::Rspec class, created a PuppetRspec autotest class, added a discovery.rb file for autotest to pick these up. Autotest still has the following problems: * it needs to be run with the proper include path: % ruby -I spec/lib/ `which autotest` * the patterns in our custom autotest handler (puppet_rspec) aren't yet fully specified (they only recognize changes in our spec files, not changes in the puppet libs which they are testing)
* File serving should work now, both recursive andLuke Kanies2007-10-241-2/+1
| | | | | | | | | | | | | | single files, across modules, local file system, and the traditional file server. This work revolves around making sure that the termini produce functional file instances, meaning that they know how to find their content or metadata, which largely comes down to setting their paths correctly. I also created a new terminus base class for the local filesystem, since there was so much common code between content and metadata.
* Adding the calls to the authorization hooks in the Indirection.Luke Kanies2007-10-231-0/+2
|
* Renaming the :local termini for metadata and contentLuke Kanies2007-10-221-4/+4
| | | | to :file.
* Link handling is now in the file serving classes.Luke Kanies2007-10-221-1/+1
| | | | | | | | | | This was done by putting all of the functionality in the Content and Metadata class (actually, in a new base class for them). There are still some issues, and there need to be integration tests between the :local (soon to be renamed :file) termini for these classes.
* Adding authorization hooks to the file_server andLuke Kanies2007-10-212-8/+2
| | | | | | | | | | | | | module_files indirection terminus types. Both hooks use the fileserver configuration, but the module_files hook only uses the 'modules' mount. Also moved all responsibility for knowing whether to use the 'modules' terminus type to the terminus selector; it was previously spread between that and the file_server terminus, which made some things annoyingly complicated. This normalizes the deprecation notices and the logic about how we make these decisions.
* Renaming the 'mounts' terminus to 'file_server', and renamingLuke Kanies2007-10-202-7/+5
| | | | tests accordingly.
* File serving now works. I've tested a couple of ways toLuke Kanies2007-10-191-1/+15
| | | | | | | | | | | | | | | | use it, and added integration tests at the most important hook points. This provides the final class structure for all of these classes, but a lot of the class names are pretty bad, so I'm planning on going through all of them (especially the file_server stuff) and renaming. The functionality is all here for finding files, though (finally). Once the classes are renamed, I'll be adding searching ability (which will enable the recursive file copies) and then adding the link management and enabling ignoring files.
* I've now split the file-serving termini into two separate types (inLuke Kanies2007-10-182-0/+86
| | | | | | | | | | | | | | | | addition to Rest): A local terminus that just uses direct file paths, and a mounts terminus that uses the file server to figure out what the path should be. It looks like it also makes sense to split the 'mounts' terminus further, so there is a 'modules' terminus used to look files up in the terminus. I've added some integration tests to verify that everything is hooked together correctly. Lastly, I added a directory for shared behaviours. There's a ton of duplication in this setup, because the Content and Metadata classes behave almost but not quite identically across the board.
* Updates to indirection stuffs. Making a better spec and migrating to it.Rick Bradley2007-09-171-1/+1
|
* Another intermediate commit. The node and fact classes are now functional ↵Luke Kanies2007-09-122-1/+7
| | | | and are used instead of the network handlers, which have been removed. There are some failing tests as a result, but I want to get this code committed before I massage the rest of the system to make it work again.